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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
One last question though. How do you know about all these rules and problems that they come up on all these commands?

Mostly it was a detailed reading of system, exec, open, qx// in perlop, the relevant parts of perlipc, execvp(3), a few bits from perlport, as well as posts such as afoken's The problem of "the" default shell and e.g. this one by salva, plus some additional information that was linked to from those docs. I also recall testing things out with e.g. strace and looking at the various modules' code while writing this node.

Correct me if I am wrong, but qw explicitly converts the strings inside the parenthesis to a list of strings right? I am confused about this part. If I come across a similar case I should explicitly define the list of commands or I can use qw?

Yes, basically qw// splits on whitespace, so the two forms you showed in your node "my @args = qw(Runbatch.exe -j dpsgl -r dpstst);" and "my @args = ('Runbatch.exe', '-j', 'dpsgl', '-r', 'dpstst');" are identical and the "Not Recommended" / "Recommended" doesn't really apply.

Note that qw// has nothing to do with qx//, they are two completely different operators that just happen to have similar names. qx// treats its argument as a single string, and you get the whitespace handling from the shell, so the same thing that happens at the command line when you type a command - this also means that whitespace can be quoted*, e.g. qx/echo "foo bar"/ is exactly like typing echo "foo bar" at the command prompt and would pass a single string "foo bar" to the command echo (assuming a "normal" shell). qw// just splits on whitespace, regardless of any quoting - qw/echo "foo bar"/ returns a list of three elements, ('echo', '"foo', 'bar"'). See also Quote Like Operators. Therefore, in e.g. system(qw/echo "foo bar"/), the shell would be avoided because system was passed more than one argument, and the echo command would receive two arguments instead of one.

* However, getting that quoting right can get very complicated if there are special characters in the strings, which is why modules like ShellQuote::Any are a better approach, or, IMHO even better, just avoid the shell in the first place.

In reply to Re^4: backticks and system() by haukex
in thread backticks and system() by ytjPerl

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2020-07-03 19:52 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found