Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Oh Wise Monks,
A need recently arose to pipe an arbitrary (short) string into a shell command and get the results. I wanted to avoid open2, and thought: the biggest issue is that some malicious person might try to inject things like "$" and quote characters, etc. No problem: I can write something that converts my input string into something that the Unix command printf (or echo -e) will interpret into the correct string, which then gets piped to the command. But then it didn't work:
$cmd = "printf 'I\\x27ll'"; print $cmd . "\n"; print `$cmd` ."\n";
I am confused because the shell gives the result I want, but backticks (and open '-|') do not!
> printf 'I\x27ll'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: backslashes in shell commands
by kcott (Archbishop) on Mar 09, 2013 at 04:04 UTC | |
by Anonymous Monk on Mar 09, 2013 at 04:24 UTC | |
by kcott (Archbishop) on Mar 09, 2013 at 05:36 UTC | |
|
Re: backslashes in shell commands
by Khen1950fx (Canon) on Mar 09, 2013 at 15:02 UTC | |
|
Re: backslashes in shell commands
by Anonymous Monk on Mar 09, 2013 at 05:30 UTC |