Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling cgi from another cgi

Status
Not open for further replies.

sonivikas

Programmer
Aug 21, 2000
10
0
0
JP
hi
help please,
i want to call a cgi program from another cgi program.
i don't want a form(calling cgi by onLoad event),
can i directly call a cgi from another cgi.
please reply me soon
thanks in advance.

[sig][/sig]
 
I'm only a beginner and not sure if this is what you want but it might work:

require 'newcgi.cgi';

Jett, [sig][/sig]
 
Hello sonivikas,
jett's suggestion of using a 'require' statement might do what you are looking for. Using a 'require' will, conceptually speaking, fold the code from the 'require'd program into the calling program so they run/act as one larger program.


Some other options.....

To launch any executable from inside a piece of Perl code, there are three options....
[red]system[/red], [red]exec[/red], and [red]backticks[/red].

exec - kills the current process and starts the specified new program
exec(secondProgram.pl);

system - starts the second program and waits for it to finish and then continues to run.
system(seconProgram.pl);

backticks or grave's accents ` - same as the system function.

Each of these functions should be wrapped in a little error checking......
unless (system(secondProg.pl)) { print "some gripe about life"; }

You could also use 'fork', but the exec and system functions take care of some house keeping that 'fork' does not.

'hope this helps.... [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
I believe that require, exec, system, & backticks all asssume the other cgi script is local. This may be what sonivikas is asking, however, to jump to a second page or cgi script that is on a different server wouldn't you use something like this?:

print &quot;Location:
I assume that params could also be passed after the $page_or_script_name and before the \n\n.

Pat
 
The redirect method will only work if you don't need to come back to the original program again, and if the called cgi program doesn't need METHOD=POST format data.

You can also use the LWP module to call a cgi script on another server. You build a form query, call the remote script using LWP, and parse the &quot;html&quot; returned from the remote script to determine the results. There should be an example of how to do that in a thread on this forum (I'm sure I've posted at least one example.) Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
<wry smile> this has just *got* to be a FAQ by now Tracy.. Mike
________________________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top