在c中编写cgi程序:system()调用。 [英] writing cgi programs in c: the system() call.

查看:80
本文介绍了在c中编写cgi程序:system()调用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用borland 5.5免费编译器在C中编写了一个cgi程序,

它在Apache服务器上运行得很好。


我唯一的问题是如果我发出一些系统调用,cgi会暂停,直到

调用结束。例如,如果在我的c程序中我有一行:


system(notepad);

我可以看到taskmanager的一个实例notepad.exe是运行的
,但是它不在我的桌面上,并且使得

系统调用的cgi程序暂停,直到我终止了notepad.exe进程。


我甚至尝试将记事本调用嵌入到.bat文件中:


system(" mybatfile.bat");


mybatfile.bat:

REM调用例程

notepad t.txt

我得到相同的结果。


如果我将mybatfile.bat重新写入一些自动完成

的例行程序,一切顺利,例如:


mybatfile.bat:

REM一个简单的固定程序

dir> t.txt


这个工作正常果然,有一个名为t.txt的新文件

创建。


从cgi调用记事本的正确方法是什么,我想象一个的/>
spawn()或exec()的变体可以解决问题;我希望这里有一些

知道。


TIA,


Jon
< br>

解决方案

jleslie48写道:


我在C中编写了一个cgi程序Borland 5.5免费编译器,

,它在Apache服务器上运行得很好。



这不是一个C问题,它更像是一个web / cgi编程问题

,答案取决于你的操作系统'支持同时运行多个进程而不是C.我会建议一个新闻组

专门研究这些东西。

同时你可能想阅读编译器的手册,看它是否有名为spawn的
函数......或ShellExec或类似函数。

< br>

jleslie48写道,在22/09/08 21:55:


我用C语言编写了一个使用borland 5.5免费的cgi程序编译器,

,它在Apache服务器上运行得很好。



嗯,CGI'在这里不是主题,也不是你的主要问题是对事物的基本错误理解。


我唯一的问题是如果我发出一些系统调用,cgi会暂停,直到

调用结束。



C标准允许它以这种方式工作。


例如,如果在我的c程序中我有一行:


system(" notepad");



现在,为什么你想要从CGI拨打记事本?

你期望记事本会在哪里运行?您希望记事本在哪里显示其

窗口?请记住,记事本是一个Windows程序,它早于

Windows内置支持网络。


< snip>


我甚至尝试将记事本调用嵌入到.bat文件中,如下所示:


system(" mybatfile.bat");


mybatfile.bat:

REM调用例程

notepad t.txt



为什么你会有什么不同?


< snip>


什么是正确的通话方式来自cgi的记事本,



没有正确的方法来执行此操作。我不知道你要做什么

来实现,但无论你是在尝试使用错误的方法。

在网络开发小组中提问(或网络论坛)关于真正的问题
你想要解决的


我想象其中一个
$ b spawn()或exec()的$ b变体将起作用;



这些都不是标准C而且我认为它们不是标准的

Windows API调用。
< blockquote class =post_quotes>
我希望这里有一些

知道。



你很幸运,这里的某个人可以看到你想做的任何事情

你完全使用了错误的方法。正如我上面所说的那样,在Web开发小组中询问你真正的问题(你不,你认为可以通过运行

记事本来解决)。

-

Flash Gordon

如果发送垃圾信息我将其发送至 sm **@spam.causeway.com

如果通过电子邮件发送给我,请使用我的回复地址

请参阅我主持的comp.lang.c Wiki a rel =nofollowhref =http://clc-wiki.net/target =_ blank> http://clc-wiki.net/


在文章< 69 ********************************** @ d77g2000hsb。 googlegroups.com>,

jleslie48< jo*@jonathanleslie.comwrote:


>我唯一的问题是如果我发布一些系统调用cgi暂停,直到呼叫结束。例如,如果在我的c程序中我有一行:

系统(记事本);

我可以通过任务管理器看到notepad.exe的实例是
运行,但它不在我的桌面上,并且使得
系统调用的cgi程序暂停,直到我杀死notepad.exe进程。



我认为这是Microsoft Windows,我不是很熟悉

with,所以这只是猜测:在其他窗口操作

系统我已经使用它对于守护进程而言非常重要。像web一样运行
服务器来启动窗口系统中显示的程序。对于

一件事,用户的桌面会出现在哪一个?

通常是一些继承的上下文(例如在unix上的X中的DISPLAY环境

变量),表示程序在

下运行窗口系统。


据推测,微软网站上有关于

如何做到这一点的文档,但我无法帮助找到它。


您还必须考虑您想要发生的事情:什么

它是否适合CGI脚本在桌面上打开某些内容?

您是否认为坐在屏幕上的人是谁?b $ b导致脚本运行?


- 理查德

-

请记得提及我/你留下的录音带。


I''ve written a cgi program in C using the borland 5.5 free compiler,
and it runs just fine on an Apache server.

My only issue is if I issue some system calls the cgi suspends until
the call finishes. for example if in my c program I have a line:

system("notepad");
I can see with the taskmanager that an instance of notepad.exe is
running, but its not on my desktop and the cgi program that made the
system call suspends until I kill the notepad.exe process.

I even tried imbedding the the notepad call in a .bat file as so:

system("mybatfile.bat");

mybatfile.bat:
REM call a routine
notepad t.txt
I get the same result.

If I re-write mybatfile.bat to some routine that completes
automatically, all goes well for example:

mybatfile.bat:
REM a simple canned routine
dir >t.txt

this works fine and sure enough, there is a new file named t.txt
created.

What is the right way to call notepad from a cgi, I imagine one of the
variations of spawn() or exec() will do the trick; I''m hoping some
here will know.

TIA,

Jon

解决方案

jleslie48 wrote:

I''ve written a cgi program in C using the borland 5.5 free compiler,
and it runs just fine on an Apache server.

This isn''t really a C question, its more a web/cgi programming question
and the answers depend on your operating system''s support for running
multiple processes at once rather than on C. I''d suggest a newsgroup
specialising in such stuff.

Meantime you might want to read your compiler''s manual to see if it has
functions called spawn... or ShellExec or similar.


jleslie48 wrote, On 22/09/08 21:55:

I''ve written a cgi program in C using the borland 5.5 free compiler,
and it runs just fine on an Apache server.

Well, CGI''s are not topical here, nor is your main problem which is a
fundamental miss-understanding of things.

My only issue is if I issue some system calls the cgi suspends until
the call finishes.

The C standard allows it to work that way.

for example if in my c program I have a line:

system("notepad");

Now, why on earth would you want to call notepad from a CGI? Where do
you expect notepad will run? Where do you expect notepad to display its
Window? Remember that notepad is a Windows program that pre-dates
Windows having built-in support for networking.

<snip>

I even tried imbedding the the notepad call in a .bat file as so:

system("mybatfile.bat");

mybatfile.bat:
REM call a routine
notepad t.txt

Why would you get anything different?

<snip>

What is the right way to call notepad from a cgi,

There is not a correct way to do this. I don''t know what you are trying
to achieve, but whatever it is you are trying to use the wrong method.
Ask in a web-development group (or web forum) about the real problem
that you are trying to solve.

I imagine one of the
variations of spawn() or exec() will do the trick;

Neither of those are standard C and I don''t think they are standard
Windows API calls either.

I''m hoping some
here will know.

You are in luck that someone here can see that whatever you want to do
you are using completely the wrong approach. As I say above, ask about
your real problem (you no, the one you think can be solved by running
notepad) in a web development group.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/


In article <69**********************************@d77g2000hsb. googlegroups.com>,
jleslie48 <jo*@jonathanleslie.comwrote:

>My only issue is if I issue some system calls the cgi suspends until
the call finishes. for example if in my c program I have a line:

system("notepad");
I can see with the taskmanager that an instance of notepad.exe is
running, but its not on my desktop and the cgi program that made the
system call suspends until I kill the notepad.exe process.

I take it this is Microsoft Windows, which I''m not really familiar
with, so this is just guesswork: in the other windowing operating
systems I''ve used it''s non-trivial for a "daemon" process like a web
server to start up programs that display in the window system. For
one thing, which user''s desktop would they appear on? There is
usually some inherited context (such as the DISPLAY environment
variable in X on unix) that indicates that a program is running under
the window system.

Presumably there is documentation on the Microsoft web site about how
to do this, but I can''t help with finding it.

You also have to consider just what it is you want to happen: what
good does it do for a CGI script to open something on the desktop?
Are you assuming that it''s the person sitting at the screen who
has caused the script to be run?

-- Richard
--
Please remember to mention me / in tapes you leave behind.


这篇关于在c中编写cgi程序:system()调用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆