This is a discussion on cgi question within the Apache Web Server forums, part of the Web Server and Related Forums category; Can a cgi written in C use "system()" to call another program (also a cgi in the same ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Can a cgi written in C use "system()" to call another program (also a cgi in
the same directory)? It acts like this call is completely ignored. I want to do this : system("CalcIt.cgi param1 param2 param3") from within a top level cgi program. the params are developed by the original CGI and are passed to CalcIt.cgi which then outputs some text after calculating some things based on those params. It would be difficult (quite) to combine them into one program (Which is why I'm attempting this) Note that the tope level cgi executes ok, i can see its output, but its like the system() call is just skipped. Thanks Eric |
|
|||
|
Eric wrote:
> Can a cgi written in C use "system()" to call another program Yes. system (char *s) system ("date") (also a cgi in the same directory)? A good practice is to use a full path, not a relative path. > It acts like this call is completely ignored. I want > to do this : system("CalcIt.cgi param1 param2 param3") Some notions. Use of system will not generate returns to a calling program. Only the exit status of the executed program is returned. If your print your system call, you will read a 0 (zero) or 1 (one) or some other non-zero number. A program called by another, unless coded to do different, will return results to Standard Output. Should your called program have a print, that will print to STDOUT. If you want to confirm your called program is running, either execute your parent program from a command line then observe what your called program prints, or have your called program print to a file. > the system() call is just skipped. Probably not, if all is correct and executable. You are simply not seeing returns which are piped to Standard Output, not your parent program. Purl Gurl |
|
|||
|
Purl Gurl wrote:
> Eric wrote: > >> Can a cgi written in C use "system()" to call another program > > Yes. system (char *s) system ("date") > > > (also a cgi in the same directory)? > > A good practice is to use a full path, not a relative path. > > >> It acts like this call is completely ignored. I want >> to do this : system("CalcIt.cgi param1 param2 param3") > > Some notions. Use of system will not generate returns to > a calling program. Only the exit status of the executed > program is returned. If your print your system call, you will > read a 0 (zero) or 1 (one) or some other non-zero number. > > A program called by another, unless coded to do different, > will return results to Standard Output. Should your called > program have a print, that will print to STDOUT. > > If you want to confirm your called program is running, > either execute your parent program from a command > line then observe what your called program prints, or > have your called program print to a file. > >> the system() call is just skipped. > > Probably not, if all is correct and executable. You are > simply not seeing returns which are piped to > Standard Output, not your parent program. > > Purl Gurl Shouldnt output from the called program (from printf) show up on the web page just like from any CGI or am i now in a different environment? (Actually i'm doing SSI with cgi's) ie: <html> <body> <#--include virtual="/cgi-bin/Prgrm1.cgi --> </body> </html> Prgrm 1.cgi issues system(Calc.cgi Param1 Param2 etc") Calc.cgi: printf("Hello\n") Shouldnt i see Hello on the web page? Its entirely possible (read 'probable') that i have an error preventing my stuff from running, but before i dug too deep i wanted to be absolutely sure i can actually do this type of thing. Thanks Eric |
|
|||
|
Eric wrote:
> Purl Gurl wrote: > > Eric wrote: > >> Can a cgi written in C use "system()" to call another program > > A program called by another, unless coded to do different, > > will return results to Standard Output. Should your called > > program have a print, that will print to STDOUT. > Shouldnt output from the called program (from printf) show up on the web > page just like from any CGI or am i now in a different environment? > (Actually i'm doing SSI with cgi's) > <#--include virtual="/cgi-bin/Prgrm1.cgi --> > Prgrm 1.cgi issues system(Calc.cgi Param1 Param2 etc") > Calc.cgi: printf("Hello\n") No. That will never show up in your webpage. You need to research and read about cgi applications. You are not understanding what processes are doing. Your "calc.cgi" is printing to STDOUT, not to your prgrm1.cgi program. Add your printf command to your prgrm1.cgi and you will see results in your webpage, making a presumption all is configured correctly and your program executes correctly. There are methods to do this but they are complex, unreliable, slow and not appropriate for cgi applications. Add a print command to your prgrm1.cgi and you will see results, but NOT from your system() called programs. Research and read about system() and cgi applications. Purl Gurl |
|
|||
|
Purl Gurl wrote:
> Eric wrote: > >> Purl Gurl wrote: >> > Eric wrote: > >> >> Can a cgi written in C use "system()" to call another program > >> > A program called by another, unless coded to do different, >> > will return results to Standard Output. Should your called >> > program have a print, that will print to STDOUT. > >> Shouldnt output from the called program (from printf) show up on the web >> page just like from any CGI or am i now in a different environment? >> (Actually i'm doing SSI with cgi's) > >> <#--include virtual="/cgi-bin/Prgrm1.cgi --> >> Prgrm 1.cgi issues system(Calc.cgi Param1 Param2 etc") >> Calc.cgi: printf("Hello\n") > > No. That will never show up in your webpage. You need to research and read > about cgi applications. You are not understanding what processes are > doing. > > Your "calc.cgi" is printing to STDOUT, not to your prgrm1.cgi program. > > Add your printf command to your prgrm1.cgi and you will see results > in your webpage, making a presumption all is configured correctly > and your program executes correctly. > > There are methods to do this but they are complex, unreliable, slow > and not appropriate for cgi applications. > > Add a print command to your prgrm1.cgi and you will see results, > but NOT from your system() called programs. > > Research and read about system() and cgi applications. > > Purl Gurl Well,it kind of works now. The problem is... in the cgi_2 called from cgi_1 if i don't print the content type header a second time in cgi_2 nothing prints from either cgi if i print the content type header in both cgi_1 and cgi_2 everything prints (shows up on the web page) **but** output from cgi_1 comes after the output from cgi_2 even tho cgi_1 writes 1st and the printing of the content type header from cgi_2 results in it being written as text on the web page. Can you point me to specific data on "system & cgi"? I did some hunting but didn't find anything to good. Thanks Eric |