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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling another script from within a script

Status
Not open for further replies.

TrevorBond

IS-IT--Management
May 21, 2003
3
OM
I need to call a script partner.po, which is on another server. This script returns some plain text which I need to parse. It is normally called from a form using POST but if I do this I cannot trap the text response.
Therefore I am trying to write a script (maybe in perl) to call this partner.po (passing some parameters). I will then look at the text it returns and parse it.
Can anyone please tell me how to call this partner.po script from within a perl script and how to specify that any output returned from this script should be put in a variable.
I initially though something like.
$response=somecommand('https:/webaddress/scripts/partner.po?params');

Any help would be very much appreciated because I am now very tired and want to go to bed.
 
I don't think I can be much help on the subject and my answer might not be correct. But it might give you something else to try before you go to bed :)

Perl has the ability to essentially download an html document. Can't remember the name of the function, but I'm sure it's in the CGI module. I also don't know how the function would react to an "interactive" page like a form, but this is the idea I have:

Use this Perl method to access your script that generates the text you want. Since the normal method is post, use get in this case. Since you could determine the submission method (post or get), and since get would not be the usual method, you could have the script automatically return the text you desire with a short command. For example, you normally post the data, but if you called the script like this: that could be the flag for your script to print out what you would normally have to post to get.

I know the Perl method I'm thinking of would allow you to save the input (i.e. the output of your script) to a file; since you can do that you can more than like also set an array variable equal to the function and use the method you suggested in your post.

Hope this makes sense. I admit it's a little crazy, but it might be worth a try. If you're still awake and/or interested in pursuing this, I'll take the time to look up the exact method I'm talking about.

Good luck.
 
The LWP module that ships with PERL has this function. It can exucute or read a remote document and return the results. Check your man pages. Look for LWP::cookbook


haunter@battlestrata.com
 
Many thanks for your posts, I really appreciate it. I did find the etc files which I assume you were talking about. Unfortunately I could not get it to run properly.
Does anyone else have a suggestion and perhaps an example script which I could run.
 
You don't have to create an HTML document with perl to read the data it returns. If you know the file structure that the other script returns then you can call it with a script, assign the values it returns to variables (maybe place it into an array and then read the array elements) then do what you want from there.

To call a script from within a script, you can use the exec command, the fork command, or just call it outright ( Which one you choose to use depends on what whether or not you want program control to return to the calling script.

There's always a better way...
 
Thanks Tviman. I guess i will need control to revert to the script since I need to parse the response.
I do know the file structure so I am fairly confident of how to parse the response. Which method of calling the script would you recommend in this case? Can you show me the line you would use to call the script?

Many thanks,

Trevor
 
Trevor,

Not knowing exactly how you're making the call to the second script, I'd opt for simplicity and:

1. call the second script - probably from and HTML page???
2. run the second script and have it call a third script that parses the results.

This saves having to worry about what the second script does. If it returns no results then it has the potential of causing problems when it returns to the calling script. Additionally, all your error handling can be done in the third script and won't muck up your original calling script.

Or...

Call the second script, parse the data in that script, and re-call the original script. (Or move on to a page rendering script?)

There's always a better way...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top