Link to home
Start Free TrialLog in
Avatar of mmcw
mmcw

asked on

Starting two script from one form using once the submit button.

Hello,

Is there a way to start out of a form two script using once the submit button. I have two scripts. I wan't to use them seperetly, but there is a place where I wan't two use them together at the same time with the same form input!

Is this possible

greeting Michel Weegerink
Avatar of ozo
ozo
Flag of United States of America image

#!/bin/perl
system("script1.cgi");
system("script2.cgi");

Avatar of icd
icd

It's not so simple as ozo suggests. Assuming the form uses a POST method the first script run will empty the stdin stream leaving no data for the second script. Also if both scripts write to stdout then there will be a problem.

I do call two scripts on one of my web sites with the condition that script1 does not read from stdin and does not write to stdout. (It only provides a log function). I don't think this will work in your case however since both scripts need access to the form input.

I am currently investigating the possibility of calling a script on another server from my own script. The outline of the method is as follows:-

form1.html calls script1.pl running on my server.
script1.pl parses the output of form1.html and opens a socket to the script2.pl URL on the other server, passing the data received from form1.html through to script2.pl

A more practical solution for you might be to create four files.

script1.pl
script2.pl
script3.pl
library.pm

script1.pl script2.pl and script3.pl are three simple scripts, each of which requires library.pm and call routines stored in library.pm

the files would look something like:-

--- script1.pl ---
#!/usr/local/bin/perl
require Library.pm
&Library::function1;

--- script2.pl ---
#!/usr/local/bin/perl
require Library.pm
&Library::function2;

--- script3.pl ---
#!/usr/local/bin/perl
require Library.pm
&Library::function1;
&Library::function2;

---

If you organise your functions correctly then I am sure you will be able to do what you want.


Well, it depends what the scripts do, and what you want to do when you use both.
I can think of cgi programs that can be combined that simply,
but I agree that reorganizing the functions would usually be a better aproach.
Also can try a dirtier approach : if the first script has read stdin , and has exhausted it , look for a premature EOF before CONTENT_LENGTH in the second one ; suppose in this case that all the form input has been eat by the first script.an proceed accordingly.
Avatar of mmcw

ASKER

Hello,

Is the library.pm file part of perl5 or where do I get this file?

greeting Michel
I think what icd was suggesting was that you could create a new file caled library.pm
into which you could put the functions you wish to use in common between your 3 scripts.

Avatar of mmcw

ASKER

Hello,

I don't understand the answers.
Maybe I did not tell the question good.
The question is a follow:
I have two perl scripts. One called: wedl.pl. The other called: form_proccessor.pl. Both they need the input out of the same html form. They both need the same email address input. I wan't to use one html form with one submit button. I wan't to push the one button and so make the two perl script go to work. Is this possible without rewriting the scripts. I don't know how to rewrite them and I need the perl script sepretely also.

greeting michel
Have you thought where the output of the two scripts should go? They both can't go to the same browser window.

Perhaps possible with cunning Javascript, two frames, one holding the input form. On submitting the form you write an 'onSubmit' handler which creates a form in the second frame, fills it in with data from the first form and submit it to wedl.pl then submits itself to form_processor.pl. Each script then outputs to a separate frame.

Very messy, not elegant, more trouble than 100 points (or in fact 200 or so in my opinion). Far simpler to re-write your scripts.

If your two scripts can take GET input, perhaps you could do something like:

#!/usr/local/bin/perl
$query = $ENV{QUERY_STRING} || <>;
print <<HERE;
Content-Type: text/html


<HTML>
<HEAD><title>two scripts</title></head>
<FRAMESET rows=300,300>
<FRAME SRC="wedl.pl?$query">
<FRAME SRC="form_proccessor.pl?$query">
</FRAMESET>
</HTML>
HERE

That might do it ozo.
ASKER CERTIFIED SOLUTION
Avatar of mac119
mac119

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial