Tuesday, November 8, 2011

How can we call another program without invokation of shell in Perl?

The system function is Perl's simplest method for accomplishing this. However, one point that should be noted here is: both this program and the Perl program from where we will be running it, will be sharing the same STDIN and STDOUT.

The syntax is like:

$status = system("myprog arg1 arg2");

This particular syntax will invoke the shell, to interpret the command line. In order to avoid the shell's involvement, the arguments for the program being executed should be passed as a list, like:
$status = system("myprog", "arg1", "arg2);

The system function does not return the program's STDOUT, rather its return value is either the program's exit status or the signal number that the process might have died from.

No comments :