The difference between perl backticks, system and exec

If you have to execute a system call using perl, there are three ways to do it. Two of them are synchronous and your perl script will pause until the system call is executed completely.

Be careful in your selection. If you choose backticks or system( ), your script will not continue execution until the process call is complete. If that process takes too long, and this is a CGI process, the calling script could timeout, and return a 504 error to your browser.

exec

This call executes a command and doesn't return. This, effectively, kills your script.

system

This call executes a command, and the calling script will wait for the command to execute before continuing. However, you can work around this by backgrounding the process:

system("perl some_process.pl &");


backticks

This call executes a command, then waits for the STDOUT output of the command, before continuing.


No comments:

Post a Comment