How is the command executed if the shell is not invoked?

By asking to system execute the specified program instead of asking the system to execute /bin/sh.

Why does adding a redirect to /dev/null increase the complexity enough to invoke the shell?

There's no point in including an entire shell in Perl. I don't know exactly what part of shell command parsing is implemented in Perl.

Finally, what method is used to execute the command if I had instead used perl's system() function instead of the backticks?

system($cmd), exec($cmd), open(my $pipe, '-|', $cmd) (and its 2-arg form) and open(my $pipe, '|-', $cmd) (and its 2-arg form) work the same way as `$cmd` (aka qx`$cmd` aka readpipe($cmd)).

system($prog, LIST) where LIST returns at least one scalar won't invoke the shell.[1]

system({ $prog } $prog, LIST) won't invoke the shell.


  1. It can in Windows.

In reply to Re^3: Effect of redirecting output to /dev/null on $? value by ikegami
in thread Effect of redirecting output to /dev/null on $? value by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.