我正在Windows上使用XAMPP (不再在办公室,明天将添加确切的版本)。
今天,我偶然发现了这种非常奇怪的行为:当使用exec()执行程序时,有些命令可以工作,而另一些命令没有给出原因就失败了。
//working
exec("dir", $output, $retval);
//$retval = 0;
//$output = array with response-lines它似乎也适用于我的wkhtmltopdf.exe:
//working as well
exec("C:\some_path\wkhtmltopdf.exe --help", $output, $retval);
//$retval = 0;
//$output = array with lines from the help-file但一旦它变得更加复杂,它就失败了:
//not working
exec("C:\some_path\wkhtmltopdf.exe C:\other_path\test.html C:\target_path\test.pdf", $output, $retval);
//$retval = 1;
//$output = array with 11 empty strings ?!?!当我用rdp将完全相同的字符串复制到服务器机器,并在windows-shell (cmd)中使用它时,它可以工作。
我不知道发生了什么- imho,非常奇怪,我得到了一个包含11个空字符串的数组。
谢谢您的帮助和建议!
发布于 2016-03-30 20:28:23
我认为问题在于论点中的斜杠:
$input = 'C:\other_path\test.html';
$target = 'C:\target_path\test.pdf';
exec("C:\some_path\wkhtmltopdf.exe '$input' '$target'", $output, $retval);您不必像这样对其进行编码,但是请尝试用'封装路径。
上述代码的结果如下:
exec("C:\some_path\wkhtmltopdf.exe 'C:\other_path\test.html' 'C:\target_path\test.pdf'", $output, $retval);您还可以尝试转义斜杠:
exec("C:\some_path\wkhtmltopdf.exe C:\\other_path\\test.html C:\\target_path\\test.pdf", $output, $retval);但这是个乱七八糟的代码。
https://stackoverflow.com/questions/36318446
复制相似问题