Re: writing cgi programs in c: the system() call.
- From: gordonb.5eekx@xxxxxxxxxxx (Gordon Burditt)
- Date: Mon, 22 Sep 2008 18:01:29 -0500
I've written a cgi program in C using the borland 5.5 free compiler,
and it runs just fine on an Apache server.
CGI runs on a *server*. A server need not even have a monitor.
Even if it does, it may be used only when the system is rebooted,
and shared with a dozen other systems via a big KVM switch.
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");
What does
system("notepad &");
do? It might avoid the suspension until the call finishes (it would
on UNIX), or it might just result in notepad complaining about its
command-line arguments.
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.
system() is not going to make anything run on a remote machine unless
the command is very specific about what machine it's supposed to run
on, and all sorts of permissions are set properly. Otherwise:
system("virus");
would be nearly unstoppable.
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 don't believe there is one.
I imagine one of the
variations of spawn() or exec() will do the trick; I'm hoping some
here will know.
Notepad needs to have a display to function. I don't know how you
give it one. Apache isn't prepared to open windows for CGIs to run
in. On UNIX, you'd need to redirect standard input and standard
output to a terminal or pseudo-terminal. Then there's the problem
that two programs (e.g. notepad and a shell) reading from the
keyboard at the same time gives you problems with the output going
to the correct place.
.
- Follow-Ups:
- Re: writing cgi programs in c: the system() call.
- From: Keith Thompson
- Re: writing cgi programs in c: the system() call.
- References:
- writing cgi programs in c: the system() call.
- From: jleslie48
- Re: writing cgi programs in c: the system() call.
- From: jleslie48
- writing cgi programs in c: the system() call.
- Prev by Date: Re: Highly efficient string reversal code
- Next by Date: Re: Pointer dereference rather than sizeof?
- Previous by thread: Re: writing cgi programs in c: the system() call.
- Next by thread: Re: writing cgi programs in c: the system() call.
- Index(es):
Relevant Pages
|
Loading