[英]Passing values to a windows batch file through PHP
我正在嘗試使批處理文件與我傳遞的命令一起運行。 出於安全原因,我們通過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
我會改用WshShell對象的“運行”命令。 無論如何,為什么要用雙引號括住pdftk命令?”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.