Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this:</p> <pre><code>my @args = ('C:/Program Files (x86)/Adobe/Reader 10.0/Reader/AcroRd32.exe'); if (system(@args) != 0) { # Can't run acroread. Oh Noes!!! die "Unable to launch acrobat reader!\n"; } </code></pre> <p>The thing about system() is that it does two different things depending on the number and type(s) of argument it gets. If the argument is an array or if there are multiple arguments, Perl assumes the first is the program to run with the rest as its arguments and it launches the program itself.</p> <p>If, however it's just one string, Perl handles it differently. It runs your command-line interpreter (typically CMD.EXE on Windows) on the string and lets it do what it wants with it. This becomes problematic pretty quickly.</p> <p>Firstly, both Perl and the shell do various kinds of interpolation on the string (e.g. replace '//' with '/', tokenize by space, etc.) and it gets very easy to lose track of what does what. I'm not at all surprised that your command doesn't work--there are just so many things that can go wrong.</p> <p>Secondly, it's hard to know for sure what shell actually gets run on Windows or what changes Perl makes to it first. On Unix, it usually doesn't matter--every shell does more or less the same with simple commands. But on Windows, you could be running raw CMD.EXE, GNU Bash or some intermediate program that provides Unix-shell-like behaviour. And since there are several different ports of Perl to Windows, it could well change if you switch.</p> <p>But if you use the array form, it all stays in Perl and nothing else happens under the hood.</p> <p>By the way, the documentation for system() and $? can be found <a href="http://perldoc.perl.org/functions/system.html" rel="nofollow">here</a> and <a href="http://perldoc.perl.org/perlvar.html#Error-Variables" rel="nofollow">here</a>. It's well worth reading.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload