【发布时间】:2014-02-25 12:29:49
【问题描述】:
我在我的 Apache 服务器上用 php 执行一个文件,我尝试了多种方法,windows 批处理文件本身确实执行并返回了结果。
我已将批处理文件简化如下
c:\code\codegen.exe "c:\47.mp3" 0 30
Codegen.exe 是 Echonest 编译的指纹识别工具。
在 Windows GUI 中运行批处理文件会返回预期的结果。
在 php over apache 中执行时出现错误。
c:\code\codegen.exe "c:\47.mp3" 0 30 [ {"error":"could not decode", "tag":0, "metadata":{"filename":"c:\\47.mp3"}} ]
返回的错误与codegen.exe找不到文件一致,即File Not Found。在该错误消息的后半部分,codegen.exe 用斜线转义斜线是正常的。
我用于执行的以下 php 脚本
<?php
$command = 'c:\\root\\test.bat';
$input = '1';
$descriptors = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
);
$ps = proc_open($command, $descriptors, $pipes);
if(is_resource($ps)){
fwrite($pipes[0], $input);
fclose($pipes[0]);
while(!feof($pipes[1])){
echo fread($pipes[1], 4096);
}
fclose($pipes[1]);
$output = proc_close($ps);
echo $output;
if($output!=0){
trigger_error("Command returned $output", E_USER_ERROR);
}
}else{
trigger_error('Could not execute command', E_USER_ERROR);
}
?>
我也试过了。 exec($cmd." 2>&1", $out, $ret);
批处理文件再次执行,但 codegen.exe 无法识别路径,我也尝试了 shell_exec,结果相同。
更多..
奇怪的是,在我自己运行 Windows 8 的笔记本电脑上,它运行良好。我没有问题,并且返回了预期的结果。我在几乎相同的设置上运行了相同的脚本,唯一的主要区别是它运行的是 Windows 7 而不是 Windows 8。
两个 apache 服务器都在管理员帐户下运行。 WHOAMI = nt权威\系统
我的感觉是它的某种权限问题,而不是文件路径。尽管我已经尝试了所有我能想到的方法并且我完全被难住了,但我们将不胜感激。
【问题讨论】:
标签: php windows apache batch-file