简体   繁体   English

在Perl中打印shell命令的输出

[英]Print the output of a shell command in Perl

我想将shell命令的输出转换为变量,例如$ result,然后在屏幕上将其打印出来,例如print $ result

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'

Just use backticks, and careful with the quoting: 只需使用反引号,并谨慎引用:

my $result = `df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print \$5 " " \$1 }'`;
print $result;

我本人只是一个学习者,但我发现此http://perldoc.perl.org/Shell.html有用...“此包作为展示用例提供,说明了一些Perl功能。不应使用它用于生产程序”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM