[英]execute awk linux command with php
i want to execute a awk linux command with php , the command is 我想用php执行awk linux命令,该命令是
mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'
i eexcute it wiht linux it works , its gave me the cpu usage in presentage, i try this in php: 我使用linux来执行它,它在演示文稿中给了我cpu的用法,我在php中尝试了这个:
$cmd= system("mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'",$retval);
echo $retval;
and 和
$cmd= passthru(" mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'",$retval);
echo $retval;
its not working , i do some searches about it so i put the awk command in variable then execute it : 它不起作用,我对其进行了一些搜索,因此我将awk命令放入变量中,然后执行它:
$var='$12 ~ /[0-9.]+/ { print 100 - $12 }';
$cmd= exec('mpstat | awk"$var"',$retval);
echo $retval;
and the output is always Array
并且输出始终是
Array
I wrote a short program to illustrate the difference: 我写了一个简短的程序来说明差异:
<?php
$cmd = system("ls", $retval);
echo "Cmd: " . $cmd . "\n";
echo "Retval: " . $retval . "\n";
?>
output: 输出:
prog.php
Cmd: prog.php
Retval: 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.