开发者

Perl: run system command with shell environment

开发者 https://www.devze.com 2023-03-23 13:22 出处:网络
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 no

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").

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号