Perl: run system command with shell environment
Trying to run perl system command with a full blown shell environment. Similar to Python's Popen with shell=True. Tried system('/bin/bash -c "something"') and that didn't work. Someone hook a non-perl guy up!
--- update ---
# ./test.pl
ENV-PATH: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:开发者_开发知识库/root/bin
sys-PATH: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
What happens with:
my $rc = system "/bin/bash", "-c", "shell command to run with arguments";
if ($rc != 0) {print "command failed: $?";}
So it appears that if you use the system() command it doesn't truly invoke a shell unless a shell meta character is seen OR the arg is in the form of a scalar. So system("echo real shell") works in my case but not system("echo", "real", "shell").
精彩评论