Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
644 views
in Technique[技术] by (71.8m points)

windows - php exec: does not return output

I have this problem: On a ISS web server, windows 7 x64 professional, zend server installed. Running this command under php:

exec('dir',$output, $err);

$output is empty, $err=1. So exec is not returing the output, it seems has some errors. Php disable_functions is empty, php is not on safe mode, is standard, I check all option. It seems to be a general errors, even search on google do not give results.

Please write every one his experince and eventual solutions or workarounds.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

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

  1. Granted execute permissions to the Internet User on c:windowssystem32cmd.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:cygwinin 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.

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.

When I used the call: $output = exec("c:\windows\system32\cmd.exe /c $batchFileToRun");

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()).

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...