Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: Strange system call failure in OS X

by afoken (Abbot)
on Feb 16, 2013 at 17:15 UTC ( #1019047=note: print w/replies, xml ) Need Help??

in reply to Re: Strange system call failure in OS X
in thread Strange system call failure in OS X

eval { $result = qx(scutil --set LocalHostName $name) };
  • qx// is the generic form of `...`
  • `...` passes a single string to the shell (except when perl is sure that a shell is not needed), so you have to handle an unknown shell with unknown behavior. Quoting is necessary to prevent shell injection, but quoting rules differ from shell to shell. See to get an idea how different shells can behave.
  • `...` does not die, eval won't catch any error in external programs, so eval is useless here.

Read the "Safe Pipe Opens" section of perlipc for a secure replacement for `...`.

The shell problem is also present in the single argument versions of system and exec, so make sure to use the multi-argument versions, which don't have this problem.


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: Strange system call failure in OS X
by karlgoethebier (Monsignor) on Feb 16, 2013 at 19:19 UTC


    #!/usr/bin/env perl + eval { qx(nose --cuke) || die qq(shit: $!\n) }; print qq(Trapped this $@) if $@; __END__ Karls-Mac-mini:monks karl$ ./ Trapped this shit: No such file or directory

    Update: I always thought that it isn't a bad idea to wrap a call to a subshell into a eval block. And i don't know what is generic with qx. It's just the same as backticks, isn't it? Just a subshell.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019047]
[choroba]: Why privately? Asking in SoPW means other people with similar problems can benefit from your questions, too.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2018-05-26 08:51 GMT
Find Nodes?
    Voting Booth?