Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Non-shell-invoking system/exec and qx//

by brian_d_foy (Abbot)
on Jun 18, 2008 at 15:26 UTC ( #692729=note: print w/ replies, xml ) Need Help??


in reply to Non-shell-invoking system/exec and qx//

Update: Duh. I should post when I'm too sleepy to think straight.

The system and exec send something to the command shell no matter how you call it (that's the point of those built-ins :). The list form just means that the elements after the command name won't be interpreted as shell meta-characters. You're still using the shell though.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review


Comment on Re: Non-shell-invoking system/exec and qx//
Re^2: Non-shell-invoking system/exec and qx//
by almut (Canon) on Jun 18, 2008 at 15:52 UTC
    ... You're still using the shell though.

    Don't think so (at least not on Unix).  For example:

    $ strace -fq -eexecve perl -e 'system "/bin/echo", "foo"' execve("/usr/local/bin/perl", ["perl", "-e", "system \"/bin/echo\", \" +foo\""], [/* 71 vars */]) = 0 [pid 27279] execve("/bin/echo", ["/bin/echo", "foo"], [/* 71 vars */]) + = 0

    So, no shell involved...

Re^2: Non-shell-invoking system/exec and qx//
by Fletch (Chancellor) on Jun 18, 2008 at 15:55 UTC

    Erm, if you pass a list they call execvp(3) directly rather than starting up a shell. If there's one argument but it doesn't have anything more exotic than whitespace it's split and passed to execvp rather than run through a shell. See the exec and system entries in perlfunc; or look under the hood at pp_system in pp_sys.c and Perl_do_exec3 in doio.c.

    Update: this is only on fork-available /bin/sh-having OSen I believe; I can't speak to what unnatural machinations are done elsewhere as my eyes started to glaze over with some of the #ifdef'ing going on.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: Non-shell-invoking system/exec and qx//
by ikegami (Pope) on Jun 18, 2008 at 17:06 UTC

    That's not true. No shell is involved in the second snippet. (Check the ppid of ps.)

    $ perl -e'system "ps -opid,ppid,cmd 2>/dev/null"' PID PPID CMD 11096 7077 -bash 5166 11096 perl -esystem "ps -opid,ppid,cmd 2>/dev/null" 13220 5166 sh -c ps -opid,ppid,cmd 2>/dev/null 19387 13220 ps -opid,ppid,cmd $ perl -e'system "ps -opid,ppid,cmd"' PID PPID CMD 11096 7077 -bash 13513 11096 perl -esystem "ps -opid,ppid,cmd" 26826 13513 ps -opid,ppid,cmd

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-08-21 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (134 votes), past polls