I'd like to get the original command line used to run a script. The goal is to pipe some output to a second
instance of the script, similar to using
open(P,"|-"), except that the new invocation will be at
the end of a sequence of piped commands. I'd like to do something like:
open( P, "| prog1 | prog2 | -" )
so that the original name and arguments of the script is preserved (it could be symlinked, and it's required that the script itself needs to know
the name) but this generates a runtime whine of
sh: - not found.
I've come up with a couple of really hacked ideas to implement this, but the easiest would involve getting the full
command line by which the script was invoked, so I could run:
$originalcmdline = some magic code here ...;
open( P, "| prog1 | prog2 | $originalcmdline" );
and pump data into P.
Anticipating at least one answer, doing something like $originalcmdline = "$0 " . join(' ',@ARGV); won't work - strings in @ARGV could contain
whitespace, quotes, double quotes, backslashes, wildcard characters, etc, making safe reconstruction of the command line a real pain.
Any suggestions?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.