http://qs321.pair.com?node_id=692729


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

Replies are listed 'Best First'.
Re^2: Non-shell-invoking system/exec and qx//
by Fletch (Bishop) 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 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 ikegami (Patriarch) 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