Possible Duplicate:
How can I store Perl's system function output to a variable?
I have tried to run a shell command in my Perl script. An example is like below:
system ("ls -al");
The result is well printed on Unix.
Is there a way to return the result to $string in my Perl script instead of returning the result on Unix?
I do not want the result to be printed on my Unix.
Use the backticks:
The ‘qx’ delimiter is a synonym for this:
This is documented here in the perlop man page.
Alternately, you can use
openwith ‘|’ like so:In this case, you’re opening a filehandle to a pipe attached to the command’s output (basically treating the output as a file). This is handy if the command takes a long time or produces more output than you want to store in memory at a time. This is documented in the Perl open manual.