通过命令作为变量时,proc_open不起作用

时间:2018-09-06 08:44:34

标签: php ubuntu rrdtool proc-open

我正在尝试使用php执行命令。当我直接将命令传递给proc_open函数时,可以像这样

$descriptorspec = array(
        0 => array("pipe", "r"),
        1 => array("pipe", "w"),
        2 => array("pipe", "w")
    );
    $cwd = '/temp/';
    $env = null;
    $blocking = false;




   echo $process = proc_open("rrdtool graph 4Rw6S0spak2zoPw9.png DEF:LOAD=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:AVERAGE DEF:LOAD_max=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:MAX DEF:LOAD_min=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:MIN AREA:LOAD#9999cc: AREA:LOAD_max#9999cc: COMMENT:'% CPU Now Ave Max\n' LINE1.25:LOAD#0000cc:' ' GPRINT:LOAD:LAST:%6.2lf%s GPRINT:LOAD:AVERAGE:%6.2lf%s GPRINT:LOAD_max:MAX:%6.2lf%s\\n COMMENT:\n HRULE:0#555555 --title='CPU' ", $descriptorspec, $pipe, $cwd,$env);

上面的代码运行良好,命令执行时没有任何错误,但是当我通过变量传递命令时,它没有执行。这是我将命令作为变量传递时的代码

$cmd="rrdtool graph 4Rw6S0spak2zoPw9.png DEF:LOAD=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:AVERAGE DEF:LOAD_max=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:MAX DEF:LOAD_min=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:MIN AREA:LOAD#9999cc: AREA:LOAD_max#9999cc: COMMENT:'% CPU Now Ave Max\n' LINE1.25:LOAD#0000cc:' ' GPRINT:LOAD:LAST:%6.2lf%s GPRINT:LOAD:AVERAGE:%6.2lf%s GPRINT:LOAD_max:MAX:%6.2lf%s\\n COMMENT:\n HRULE:0#555555 --title='CPU' "
   $descriptorspec = array(
        0 => array("pipe", "r"),
        1 => array("pipe", "w"),
        2 => array("pipe", "w")
    );
    $cwd = '/temp/';
    $env = null;
    $blocking = false;




   echo $process = proc_open($cmd, $descriptorspec, $pipe, $cwd,$env);

此代码仅返回进程数,但未创建文件

0 个答案:

没有答案