stakor
asked on
Called Program Status
I have a perl script that calls another program in such a way that it records the results of the command in a string. i.e.
$program_results = `program $ARGV[0] `;
I would like to have perl check the status of the command, for instance did it complete with a non-error of zero - or did it error out somehow. Is there a way of checking the status of a program that is run while capturing the output?
$program_results = `program $ARGV[0] `;
I would like to have perl check the status of the command, for instance did it complete with a non-error of zero - or did it error out somehow. Is there a way of checking the status of a program that is run while capturing the output?
ASKER
I don't fully understand. I am hoping to capture everything that program would normally print to screen in $program_results. I would also like to have the ability to run a check on another variable to see the exit status. I didn't know if there was a variable built into perl that would show the exit status of the last command or something along those lines.
If I understand the program snippet above, $program_results is the exit variable?
If I understand the program snippet above, $program_results is the exit variable?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So if everything ran correctly, $program_retval should be equal to zero?
if ($program_retval != 0) {
<freak_out>
};
if ($program_retval != 0) {
<freak_out>
};
clockwatcher gets it right with $?
Learn something every day.
Learn something every day.
Open in new window
I added code to prevent other output produced by program from also being returned, but this is up to you.