【问题标题】:Why shell_exec return null为什么 shell_exec 返回 null
【发布时间】:2020-09-15 23:29:14
【问题描述】:

我有一个在 cmd 中运行良好的 shell 命令, 但是当我想使用 shell_exec() 函数在 php 中运行这个命令时,它返回 null 给我,我尝试使用 exec() 函数,同样的事情。

我读过一篇文章说如果发生错误,shell_exec 返回 NULL。

这就是我在 yii2 代码中所做的:

$strPath = "C:/inetpub/wwwroot/MyApp";
chdir ($strPath);
return $output = shell_exec ('php app/console command ........');

这个命令是它的 symfony 命令。 知道项目在windows server中。

我们如何解决这个问题? 确实有问题

请帮帮我

谢谢

【问题讨论】:

  • 您使用的是 Symfony 框架还是只是组件?你从哪里打电话给shell_exec(),是一个 Symfony 控制器,还是从哪里来的?
  • "在 Windows 上,底层管道以文本模式打开,这可能导致函数无法进行二进制输出。请考虑在这种情况下使用 popen()。"
  • @Arleigh Hix 我从 yii2 控制器调用了 sell_exec(),并命令它是 symfony 命令
  • 为什么不使用exec

标签: php symfony yii2


【解决方案1】:

来自https://www.php.net/manual/en/function.shell-exec.php

Note: This function can return NULL both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. exec() should be used when access to the program exit code is required.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 2022-12-26
    • 2016-12-28
    • 2015-11-25
    • 2015-07-04
    • 2019-09-29
    • 2015-02-25
    相关资源
    最近更新 更多