[英]Getting response from unix commands executed via PHP
I would like to list the Cron tasks for a given user in the browser. 我想在浏览器中列出给定用户的Cron任务。 I am using the following, which works fine via SSH: 我正在使用以下内容,它可以通过SSH正常运行:
crontab -u username -l crontab -u用户名-l
Which outputs something like: 输出如下:
*/2 * * * * cd /home/username/public_html/cron; php -q -c ./ cron_4.php
*/2 * * * * cd /home/username/public_html/cron; php -q -c ./ cron_3.php
*/2 * * * * cd /home/username/public_html/cron; php -q -c ./ cron_2.php
0 0 * * * cd /home/username/public_html/cron; php -q -c ./ cron_1.php
However, when I try to do it via PHP... 但是,当我尝试通过PHP进行操作时...
$return = array();
$command = "crontab -u username -l";
passthru($command, $return);
echo "<pre>";
var_dump($return);
echo "</pre>";
I only get... 我只会
int(1)
Whereas I was expecting an array containing each of the above lines. 而我期待的是包含上述各行的数组。
How can I achieve the expected result via PHP? 如何通过PHP达到预期的结果?
I ended up using exec()
我最终使用了exec()
$r=[];
exec($command,$r);
The actual problem was something to do with permissions and is irrelevant to the question as I stated it. 实际的问题与权限有关,与我所说的问题无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.