This runs an external command for you, then carries on with the script. It always
returns, and the value it returns goes into
This means you can test to see if the program worked. Actually you are testing to see if
it could be started, what the program does when it runs is outside your control if you use
This example demonstrates
system in action.
Run the 'vol' command from a command prompt first if you are not familiar with it. Then
run the 'vole' command. I'm assuming you have no cute furry executables called vole on
your system, or at least in the path. If you do have an executable called 'vole', be
creative and change it.
system("vole"); print "\n\nResult: $?\n\n"; system("vol"); print "\n\nResult: $?\n\n";
As you can see, a successful system call returns 0. An unsuccessful one returns a value which you need to divide by 256 to get the real return value. Also notice you can see the output. And because
system returns, the code after the first
system call is executed. Not so with
exec, which will terminate your perl script if it is successful. Perl's usual use of single and double quotes applies as per variable interpolation.