Will you please comment on the disadvantages of this method?

It depends on where your input is coming from and what it contains, but in the general case, wherein the input *might* contain shell metacharacters and *might* potentially even be constructed with malice, the shell *might* give complete control of your system (or, at least, as much control as is available to the user the code is running as) to whoever constructed the input. More likely, however, a shell metacharacter will get included randomly by someone who is not aware of the implications and cause apparently random breakage. For example, you'll put an ampersand in the input one time without thinking, and Weird Stuff(TM) will happen, and you'll have to track down the problem and figure out that the ampersand needs to be escaped, and so on. This is bad: your program is not robust, and input that's a little different from what was anticipated causes it to unexpectedly fail.

It's also something of a portability nightmare, since different shells have different metacharacters that behave in different ways. This can create all kinds of zany debugging fun.


;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print

In reply to Re: feeding text to a process, and capturing its output, safely by jonadab
in thread feeding text to a process, and capturing its output, safely by merlyn

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.