且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php exec:不返回输出

更新时间:2023-02-22 14:36:42

PHP手册的相关部分有一些帖子,例如这一个

There are a few posts to the relevant sections of the PHP Manual such as this one:


我无法使用PHP exec命令执行任何批处理
文件。执行其他命令(即dir)工作正常。但是如果我
执行了一个批处理文件,我收到了exec命令的输出。

I was having trouble using the PHP exec command to execute any batch file. Executing other commands (i.e., "dir") works fine). But if I executed a batch file, I receieved no output from the exec command.

我的服务器设置包括运行
IIS6和PHP 5.2.3的Windows Server 2003服务器。在这台服务器上,我有:

The server setup I have consists of Windows Server 2003 server running IIS6 and PHP 5.2.3. On this server, I have:


  1. 对c:\windows \ system32 \ cmd.exe上的Internet用户授予执行权限。

  2. 授予所有人 - >完全控制编写批处理文件的目录。

  3. 授予每个人 - >完全控制整个c :\ cygwin \ bin目录及其内容。

  4. 授予Internet用户以批处理方式登录权限。

  5. 指定完整路径

  6. 测试了从服务器上的命令行运行的这些脚本,它们工作得很好。

  7. 确保%systemroot% \ system32在系统路径中。

  1. Granted execute permissions to the Internet User on c:\windows\system32\cmd.exe.
  2. Granted Everyone->Full Control to the directory in which the batch file is written.
  3. Granted Everyone->Full Control on the entire c:\cygwin\bin directory and its contents.
  4. Granted the Internet User "log on as batch" permissions.
  5. Specified the full path to each file being executed.
  6. Tested these scripts running from the command line on the server and they work just fine.
  7. Ensured that %systemroot%\system32 is in the system path.

事实证明,即使在服务器上安装了以上所有内容,我也是如此b $ b必须在exec调用中指定cmd.exe的完整路径。

It turns out that even with all of the above in place on the server, I had to specify the full path to cmd.exe in the exec call.

当我使用调用时: $ output = exec( C:\\windows\\system32\\cmd.exe
/ c $ batchFileToRun);

然后一切正常。在我的情况下, $ batchFileToRun 是批处理文件的
实际系统路径(即调用
realpath()的结果)。

then everything worked fine. In my situation, $batchFileToRun was the actual system path to the batch file (i.e., the result of a call to realpath()).

exec shell_exec 手册页。也许通过它们可以得到它并为你工作。

There are a few more on both the exec and shell_exec manual pages. Perhaps following through them will get it up and working for you.