【问题标题】:Php exec command not working on Windows, works on command linePhp exec 命令在 Windows 上不起作用,在命令行上工作
【发布时间】:2012-01-16 13:29:38
【问题描述】:

我正在尝试通过 PHP 的 exec 函数执行以下命令:

D:\\pstill -F a4 -2 -c -c -c -c -g -i -t -K -d 700 -a 4 -m XimgAsCMYK -m Xspot -m Xoverprint -o D:\\outputfile.pdf D:\\new.jpg  

它不会产生任何输出。但是如果我直接将命令粘贴在命令行上,那么它就可以工作......

注意:直接在命令行运行需要一点时间来完成。

【问题讨论】:

  • 您是否收到任何错误消息?您能否告诉我们您的代码(不仅仅是您正在执行的命令)?
  • exec("pstill -F a4 -2 -c -c -c -c -g -i -t -K -d 700 -a 4 -m XimgAsCMYK -m Xspot -m Xoverprint -o D:\\outputfile.pdf D:\\input.jpg");
  • 确保您的网络服务器的用户 ID 具有执行 pstill 的适当权限,以及 D:\ 根目录/驱动器的读/写权限。

标签: php command-line


【解决方案1】:

我建议在这里使用shell_exec 而不是 exec 函数。 shell_exec 通过适当的 shell(Windows / Unix 等)执行命令,并将完整的输出作为字符串返回给您。

【讨论】:

    【解决方案2】:

    如果你的命令是这样的:

    exec("pstill -F a4 -2 -c -c -c -c -g -i -t -K -d 700 -a 4 -m XimgAsCMYK -m Xspot -m Xoverprint -o D:\\outputfile.pdf D:\\input.jpg");
    

    PHP 会转义反斜杠,因此到达 shell 的命令是 ... D:\outputfile.pdf D:\input.jpg。您必须双重转义反斜杠:一次用于 PHP,一次用于 shell。

    exec("pstill -F a4 -2 -c -c -c -c -g -i -t -K -d 700 -a 4 -m XimgAsCMYK -m Xspot -m Xoverprint -o D:\\\\outputfile.pdf D:\\\\input.jpg");
    

    【讨论】:

      【解决方案3】:

      对我来说,解决办法是

      在终端窗口而不是服务中运行 apache。

      看到这个帖子: apache service php exec not working

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-21
        • 1970-01-01
        • 2016-09-09
        相关资源
        最近更新 更多