PHP启动windows应用程序、执行bat批处理、执行cmd命(2)


++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:28:52
$lastLine
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:28:52
root      5375  5373  0 16:28 pts/1    00:00:00 grep magent
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:28:52
$retVal
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:28:52
0

【exec】

复制代码 代码如下:


<?php
set_time_limit(0);
define('ROOT_PATH', dirname(__FILE__));

include ROOT_PATH . '/include/global.func.php';

$cmdTest = 'ps -ef | grep magent';

$lastLine = exec($cmdTest, $output, $retVal);

write_log('$lastLine');
write_log($lastLine);

write_log('$output');
write_log($output);

write_log('$retVal');
write_log($retVal);
?>

输出:

复制代码 代码如下:


++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:25:00
$lastLine
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:25:00
root      5360  5358  0 16:25 pts/1    00:00:00 grep magent
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:25:00
$output
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:25:00
Array
(
    [0] => root      2838     1  0 15:39 ?        00:00:00 magent -u root -n 51200 -l 192.168.137.100 -p 12001 -s 192.168.137.100:11211 -b 192.168.137.100:11212
    [1] => root      5358  5356  0 16:25 pts/1    00:00:00 sh -c ps -ef | grep magent
    [2] => root      5360  5358  0 16:25 pts/1    00:00:00 grep magent
)

++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:25:00
$retVal
++++++++++++++++++++++++++++++++++++++++++
2014-10-15 16:25:00
0

结论:

如果需要详细的输出结果,那就用exec()吧!我一般用exec()执行外部命令!

参考:


您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b93dfaf4b86695f7195595d0f7291b36.html