dqm4977 2014-10-01 20:55
浏览 44
已采纳

通过PHP将值传递给Windows批处理文件

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
  • 写回答

1条回答 默认 最新

  • doulv1760 2014-10-01 21:03
    关注

    I would use the "run" command of the WshShell object instead. In any case, why do you have the pdftk command surrounded by double quotes"?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3