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

Returning a value from one perl to another 2

Status
Not open for further replies.

Tve

Programmer
May 22, 2000
166
FR
Hi,<br><br>Supposing that perl code A calls up perl code B to do a check before continuing it's own execution, i have two questions:<br><br>1. How do I call perl code B from A? Using system()?<br>2. How do I return the answer from B to A? Writing to file?<br><br>Thanks
 
you can call a perl script using system in the same way you'd call the same script from the command line<br><br>system() returns a value from the program it runs - you return a value from a perl script with the exit function<br><br>exit 2<br><br>for example<br> <p>Mike<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>Please don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
additionally, <i>system</i> returns a status, not data from code B.&nbsp;&nbsp;If you want to catch data printed from B to A, you could use backticks or you could fork code B as a child process using <b>-¦</b> or <i>fork</i>.<br>The backtick approach might look like this.....<br>Code A runs code B via the backticks and catches prints from code B.<br><br><b>Code A:</b><br>#!/usr/local/bin/perl<br>$stuff = `codeB startedInCodeA`;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# run codeB and catch output of B<br>print &quot;In codeA, codeB returned - $stuff.\n&quot;;<br><br><b>Code B:</b><br>#!/usr/local/bin/perl<br>$var = @ARGV[0];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# first command line arg<br>print &quot;$var&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# print var to STDOUT which goes <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# back to the parent process, codeA.<br><br><br>Forks are a little more complicated........ask if the above does not help.<br><br>Good Luck......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top