What is the difference between these two usages of system?
$cmd = "/my/code.pl";
$status = system("$cmd $var1");
vs
$cmd = "/my/code.pl";
$status = system("$cmd", "$var1");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first (one string) invocation of
systemruns the system shell to run the command, and (amongst other things) means that the arguments to the command (from$var1) will undergo shell expansion.The second version with plural arguments bypasses the system shell and the arguments undergo no further shell processing. It is generally the recommended way of doing things. Note, however, that it means you have to worry about I/O redirection. If that’s an issue, then the first form (used carefully) is simpler. Alternatively, explore CPAN to find modules to assist – there are bound to be some.