Uh... Perl's system() is not exactly broken, but not easy to handle either. Most importantly, what gets returned by system() is not the return code of the command executed:
-1 means the command failed to start, "inspect $! for the reason";
if the process terminated normally, the 8 low-order bits of the return value are 0, the 8 high-order bits contain the exit() value (i.e., the return code of the command executed);
if the process terminated due to a signal, the 8 high-order bits contain 0, and the 8 low-order bits contain the signal value;
if the process was stopped, the low-order bits contain WSTOPFLG, and the high-order bits contain the signal that caused the process to stop.
Have fun...
Every good solution is obvious once you've found it.
Solar wrote:Uh... Perl's system() is not exactly broken, but not easy to handle either. Most importantly, what gets returned by system() is not the return code of the command executed:
Is there any alternative to executing commands from within perl?
No, absolutely correct. foo gets executed by the shell, output gets piped to the file handle.
You shouldn't use this style of file handle; there's something called "anonymous file handles" where you assign a file handle reference to a variable or somesuch... I don't use Perl except for quick&dirty, so I never got into the fine print much.
Every good solution is obvious once you've found it.