To expound a bit on dws's remarks: you would not want to run that system call if the value of $file1 was something like "/dev/null;rm -rf *"... The point would be to make sure that the variables being used are not so "weird" as to wreak havoc when they are passed "successfully" to the shell.

To be safe, the values of $program1, $program2, etc. would be "known", drawn from some limited set of alternatives, and the values of $file1, $file2 would be pre-conditioned to eliminate any characters that would cause problems in the shell (esp. semicolons, pipe symbols, ampersands and such) -- either remove them outright or replace them with safe punctuation characters, underscores, or whatever.

But if you need to handle some oddball file names, you might try the following alternative to the system call:

$file1 = s/(\W)/\\$1/; # and similarly for other filenames open( SH, "| /bin/sh"); print SH "$program1 $file1 | $program2 | $program3 > $file2\n"; close SH;
I'm not saying this is guaranteed to work for you, but it's something to try (especially if you were intending to use the system call inside a loop: open the shell before going into the loop, then just print a command line to the shell on each iteration -- see a sample of this in a utility I posted a while ago).

In reply to Re: system, pipes, shell, quoting by graff
in thread system, pipes, shell, quoting by superpete

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.