Perl supports three ways (that I know of) of running external programs:
system
:
system PROGRAM LIST
as in:
system "abc";
backticks as in:
`abc`;
running it through a pipe as in:
open ABC, "abc|";
What are the differences between them? Here's what I know:
In list context, backticks returns a list of lines that were the output of the command. In scalar context, it returns them as a single string joined with newlines.
exec - Perldoc Browser. The exec function executes a system command and never returns; use system instead of exec if you want it to return. It fails and returns false only if the command does not exist and it is executed directly instead of via your system's command shell (see below).
Perl's system command provides a way to execute a shell command on the underlying platform. For example, if you are running on a Unix platform, the command: system("ls -l") will print a long listing of files to stdout.
system()
: runs command and returns command's exit status Also backticks redirects the executed program's STDOUT to a variable, and system sends it to your main program's STDOUT.
The perlipc documentation explains the various ways that you can interact with other processes from Perl, and perlfunc's open documentation explains the piped filehandles.
There are also modules that handle these details with the cross-platform edge cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With