When you run a process in the background via the shell (with the &), the return value is always zero.
Not so!
system, exec, and fork can all fail and depending on the function, return a non-zero value if the system cannot fork at the time (say, if there is a runaway process running that has forked too many times). Or actually, on failure fork returns undef, exec returns false, and system returns whatever the secondary process returned. Normal programs return 0 on success but are expected to return non-zero values on failure. So system is perfectly capable of returning non-zero values. When that happens, something wrong has happened in the program that system was running.
The return code of the program is in $? >> 8 so check that when it fails.
In reply to Re^2: multi-command sytem call
by diotalevi
in thread multi-command sytem call
by water
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |