【问题标题】:Not able to run .sh in shell_exec()无法在 shell_exec() 中运行 .sh
【发布时间】:2020-02-07 18:45:26
【问题描述】:

我正在尝试在 php 中运行 shell 脚本。虽然 shell_exec() 正在工作 (我曾尝试运行 $result = shell_exec('ls') 并且效果很好), $result = shell_exec('sh /where/the/file/is/test.sh') 似乎无法运行。它不会在 $result 中输出。

注意:test.sh 是 rwxrwxrwx

【问题讨论】:

  • 您的test.sh 是做什么的?我有一个简单的echo "Hello World",它与shell_exec('sh ./test.sh');完美配合。
  • 我有echo 'hi'
  • www-data用户下从控制台执行时运行正常吗?也可以尝试shell_exec('sh /.../test.sh 2>&1') 看看执行是否失败并出现错误。
  • 哦! $结果显示sh: 0: Can't open /where/the/file/is/test.sh。我该如何解决?
  • 将 .sh 文件放在 $PATH 环境变量中的任何目录中,供执行 shell_exec() 的用户帐户使用;

标签: php shell


【解决方案1】:

尝试使用

shell_exec('./test.sh');

或者 shell_exec('../test.sh');

或者 shell_exec('.test.sh');

部分版本不支持

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多