使用PHP网页中的输入参数运行.exe [英] Run a .exe with input parameters from PHP web page

查看:483
本文介绍了使用PHP网页中的输入参数运行.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试从PHP网页(当前使用exec())中运行可执行文件.从命令行运行时,该程序采用两个参数.我不确定最好的方法是用PHP运行它.

I'm currently trying to get an executable to run from within a PHP web page (currently using exec()). The program takes two arguments when run from the command line; I'm not sure what the best method would be to run it with PHP.

特别是,可以使用以下语法从命令行运行.exe:

In particular, the .exe can be run from the command line using the syntax:

my_program.exe input_file_name.txt / output_file_name.txt

程序处理输入文件中的数据,并将处理后的数据放入输出文件中.从命令行(在Windows中),这一切都可以正常工作. .exe是用Visual Basic编写的(不是我编写的).

The program processes the data in the input file and puts the processed into into the output file. This all works fine from the command line (in Windows). The .exe is written in Visual Basic (it wasn't written by me).

我知道我通常可以通过执行以下操作来给exec()一个参数:

I know I can normally give exec() a parameter by doing something like:

exec('my_program.exe "example input parameter"');

如果编写.exe是为了接受argv()的输入,我已经进行了测试.我尝试了一些类似的事情:

if the .exe is written to take input from argv(), which I've done for testing. I tried a few things like:

$argument = "C:\wamp\www\web_dev\test\input.txt / C:\wamp\www\web_dev\test\output.txt";
exec('C:\wamp\www\web_dev\test\my_program.exe $argument');

哪个没有解决. (如果相关,我目前正在尝试使其在我的本地主机上运行.)

Which didn't work out. (I'm currently trying to get it working on my localhost, in case that's pertinent..)

我相信,由于.exe完成了打开,写入和关闭输入和输出文件的所有工作,因此我只需要弄清楚如何编写将以适当方式执行程序的PHP命令即可.

I believe, since the .exe does all the work of opening, writing to, and closing the input and output files, that I just need to figure out how to code a PHP command that will execute the program in the appropriate fashion.

我见过与此线程类似的线程,所以我希望我不要再提出任何要求.我找不到与这种情况完全相关的线程.

I've seen similar threads to this one, so I hope I'm not re-asking anything; I wasn't able to find a thread that quite pertained to this situation.

编辑:如果有帮助,我正在努力的总体目标是创建一个网络界面,该界面允许用户上传文件,然后调用已提供的可执行文件(上面提供了上面提到的命令行指令给我),并为用户生成了带有处理过的数据的输出文件.

if it helps, the overall scope I'm working towards is to create a web interface that allows a user to upload a file, then invokes the executable I've been given (which was given to me with the command-line instructions mentioned above) on it and produces an output file for the user with the processed data.

推荐答案

基本的PHP语法错误:您使用了错误的引号.请使用双引号代替.

basic PHP syntax error: you're using the wrong quotes. Use double-quotes instead.

exec("C:\wamp\www\web_dev\test\my_program.exe $argument");
     ^---                                              ^---

单引号(')不会将变量插值到字符串中.您正在尝试传递文字$a等作为参数,而不是该变量的值.

single quotes (') do NOT interpolate variables into the string. You're trying to pass a literal $, a, etc... as an argument, not the value of that variable.

这篇关于使用PHP网页中的输入参数运行.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆