Sunday, May 10, 2009

Executing system command from a perl program and capturing the output

http://www.perlhowto.com/executing_external_commands

method use if ...
system() you want to execute a command and don't want to capture its output
exec you don't want to return to the calling perl script
backticks you want to capture the output of the command
open you want to pipe the command (as input or output) to your script

2 comments:

  1. IPC::System::Simple if you want to capture all data.

    ReplyDelete
  2. A unique property of the system call - returns false on success and true on failure. Add that because people would be doing this

    perl -le 'system("ls") and print "success"' which will fail

    ReplyDelete