Bluehost.com Web Hosting $6.95

cgi question

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 ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-17-2005
Eric
 
Posts: n/a
Default cgi question

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

  #2 (permalink)  
Old 12-17-2005
Purl Gurl
 
Posts: n/a
Default Re: cgi question

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
  #3 (permalink)  
Old 12-17-2005
Eric
 
Posts: n/a
Default Re: cgi question

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

  #4 (permalink)  
Old 12-17-2005
Purl Gurl
 
Posts: n/a
Default Re: cgi question

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
  #5 (permalink)  
Old 12-17-2005
Eric
 
Posts: n/a
Default Re: cgi question

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:17 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0