I am trying to get a batch file to run with commands that I am passing it. For security reasons we execute our commandline calls through WScript.Shell
This is what my batch file looks like:
@echo off
pushd \\theServer\wwwroot\tuition\uploads\
pdftk PDF_Template.pdf fill_form %1 output %2 need_appearances
popd
I am then passing the vars to the bat file like so:
$WshShell = new COM("WScript.Shell");
$WshShell->exec(getcwd().'\uploads\test.bat 1412194760.fdf output.pdf');
When I run the bat file from the server, everything works fine. However, not getting any results when it runs from php.
This example worked just fine when I had the full paths in there which I am trying to get rid of now using the code above.
$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');
Can you see anything obvious I am doing wrong?
Update:
As a test I hard coded the values into the batch file:
pdftk Educational_Assistance_Request_Form_North_America.pdf fill_form 1412194760.fdf output output.pdf need_appearances
I then tried just running the file with both run
and execute
$WshShell->run(getcwd().'\uploads\test.bat');
$WshShell->exec(getcwd().'\uploads\test.bat');
This test also failed.
Maybe its a permission error for shell running a batch file?
FIX: So even though I was running the exec command in this location:
getcwd().'\uploads\test.bat
When I logged it, it was only running it in the cwd
and ignored the uploads folder.
I changed the batch file to this and it now works fine:
pdftk uploads/Educational_Assistance_Request_Form_North_America.pdf fill_form uploads/%1 output uploads/%2 need_appearances