Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Problem with 'system' function in Windows Vista

by ikegami (Pope)
on Mar 20, 2007 at 17:52 UTC ( #605722=note: print w/ replies, xml ) Need Help??


in reply to Problem with 'system' function in Windows Vista

Your snippet makes no sense (although none of this explains the crash).

  • system(1, ...) does not return zero on success.
  • system(1, ...) does not return the exit code of the child. It returns the PID of the child.
  • $? is being checked before the child has finished running, so its value is meaningless.

Did you really mean to execute the child asynchronously? You're acting as if you want the child to end before proceeding. If so, you want system(@cmd), not system(1, @cmd).


Comment on Re: Problem with 'system' function in Windows Vista
Select or Download Code
Re^2: Problem with 'system' function in Windows Vista
by diotalevi (Canon) on Mar 20, 2007 at 18:49 UTC

    Since this is Windows you might as well say system( "@commands" ) because that's what's really happening anyway. At least its clear then that everything in @commands has to be properly shell quoted.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      Yes and no.

      • No, system does quote (in ActivePerl, at least).

        @cmd = ( 'echo', 'identifier', 'a string', '"pre quoted"' ); system(@cmd); # identifier "a string" "pre quoted" $cmd = "@cmd"; system($cmd); # identifier a string "pre quoted"
      • Yes, sending the command as a string instead of a list of arguments is a good idea in Windows. In Windows, command line parsing is done by the child. That means every program has its own mechanism to quote and escape its parameters (*). In turn, that means that system (or the underlying library) must guess at how the child wants its arguments quoted and escaped.

        Avoid the guessing if possible and provide to the child what the child will receive.

      * — If any! When quoting is supported, it's usually double quotes. As for an escaping mechanism, I don't remember ever seeing one, so good luck trying to pass a double quote to a program...

        Escaping, when possible was usually just another doublequote: "bar ""baz" -> bar " baz.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://605722]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-12-28 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls