Perl offers three slightly different mechanisms for executing external commands:
- Backticks or qx//
- Using system
System will execute the $command with @arguments and return to your script when finished.
You may check $! for certain errors passed to the OS by the external application.
# For example:
system( "sh", "script.sh", "--help" );
system("sh script.sh --help");
Read the documentation for system for the nuances of how various invocations are slightly different.
- Using exec
This is very similar to the use of system, but it will terminate your script upon execution.
Again, read the documentation for exec for more.
- Using backticks or qx//
The backtick operator and it's equivalent qx// excute the command and options
inside the operator and return that commands output to STDOUT when it finishes.
my $output = `script.sh --option`;
my $output = qx/script.sh --option/;
There are also ways to run external applications through creative use of open, but this is advanced use;
read the documentation for more.