We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

mmcw
mmcw asked
on
Medium Priority
280 Views
Last Modified: 2013-12-25
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
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

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

icd

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


ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

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

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

Author

Commented:
Hello,

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

greeting Michel
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

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

Author

Commented:
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
icd

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

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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

icd

Commented:
That might do it ozo.
Commented:
The previous comments suggest a method which should work (a bit messily), but why wouldn't you simply have the first script output a redirect to the second, so that the browser would repost the data to the second script?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.