Yes there are a number of posts and sites that talk about using perl to run other scripts and to get the exit status. However I haven't seen any that explain the behavior I'm seeing and I'm just plain confused.
I have a bash script prints out some stuff and then at the end does an "exit 101". I want my perl script to capture both the content of what the script prints and the 101 value of the exit code.
So of course I tried:
myscript.sh
my_perl_script.pl#!/bin/bash echo "foo" exit 101
Running my_perl_script.pl results in:my $cmd = "myscript.sh"; my $content = `$cmd`; my $exitcode = $?; print "Content: $content\n"; print "Exit Code: $exitcode\n";
Content: foo Exit Code: 25856
Now I have no idea how it got 25856 from 101 (well it does seem to be 101 times that magical 256 number, but I'm sure it isn't that simple).
In bash if I run myscript.sh and echo $? I get the expected 101. So something weird I think is happening with the backticks.
In reply to getting the bash exit code by xorl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |