Reputation: 312
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.
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
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).
I know I can normally give exec()
a parameter by doing something like:
exec('my_program.exe "example input parameter"');
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..)
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.
Edit: 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.
Upvotes: 3
Views: 18566
Reputation: 360632
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");
^--- ^---
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.
Upvotes: 7