我正在尝试使用我传递的命令来运行批处理文件。出于安全原因,我们通过WScript.Shell
这是我的批处理文件的样子:
@echo off
pushd \\theServer\wwwroot\tuition\uploads\
pdftk PDF_Template.pdf fill_form %1 output %2 need_appearances
popd
然后我将vars传递给bat文件,如下所示:
$WshShell = new COM("WScript.Shell");
$WshShell->exec(getcwd().'\uploads\test.bat 1412194760.fdf output.pdf');
当我从服务器运行bat文件时,一切正常。但是,从php运行时没有得到任何结果。
这个例子工作得很好,当我在那里有完整路径时,我试图摆脱现在使用上面的代码。
$WshShell->exec('"pdftk" C:\\inetpub\\wwwroot\\tuition\\uploads\\Educational_Assistance_Request_Form_North_America.pdf fill_form C:\\inetpub\\wwwroot\\tuition\\uploads\\'.$fdf_file.' output C:\\inetpub\\wwwroot\\tuition\\uploads\\'.$newPDF.' need_appearances');
你能看到任何明显我做错的事吗?
更新
作为测试,我将值硬编码到批处理文件中:
pdftk Educational_Assistance_Request_Form_North_America.pdf fill_form 1412194760.fdf output output.pdf need_appearances
然后我尝试使用run
和execute
$WshShell->run(getcwd().'\uploads\test.bat');
$WshShell->exec(getcwd().'\uploads\test.bat');
此测试也失败了。
也许是运行批处理文件的shell的权限错误?
FIX: 即使我在这个位置运行exec命令:
getcwd().'\uploads\test.bat
当我记录它时,它只在cwd
中运行它并忽略了uploads文件夹。
我将批处理文件更改为此文件现在可以正常工作:
pdftk uploads/Educational_Assistance_Request_Form_North_America.pdf fill_form uploads/%1 output uploads/%2 need_appearances
答案 0 :(得分:0)
我会使用" run"改为使用WshShell对象的命令。在任何情况下,为什么你的pdftk命令被双引号"?
包围