in reply to Executing a perl script from a perl script???
the \Q and \E escape any strange characters in var1 and var2 so they don't screw up the call (like & and ' etc), and script2.pl will see those values in the @ARGV array var1 in $ARGV[0] and var2 in $ARGV[1]... the exit value of script2.pl will be in $?$resp = `script2.pl \Q$var1\E \Q$var2\E`;
if script2.pl puts out a lot of info you may want something more like
that does essentially the same thing as the ``, except you get the output of script2.pl line by line in $_ in the while loop. (chomp removes the trailing \n from $_)open(CMD, "script2.pl \Q$var1\E \Q$var2\E") or die $!; while(<CMD>) { chomp; print ">>$_\n"; } close CMD;
Finally there is system, which returns the exit code of the script, not the output, the output just goes normally to STDOUT
if(system("script2.pl \Q$var1\E \Q$var2\E")){ print "Error running script2.pl!\n"; }
- Ant
- Some of my best work - Fish Dinner
|
|---|