Reputation: 153
I've got a bit of a mess here.
Windows Server 2008 R1 + IIS6 + PHP5.3.10
I have a PHP script which connects to a small, local mssql database, performs a search and puts the results into variables. There are 6 columns in the db though only 4 of them are worth passing.
I have a console python program (in 2.7 flavor) on this server. It takes 4 arguments (target email address, subject, body and key (key is a 64 alphanum string). This python program then puts all of this into an HTML template (which is defined in the program itself) and emails it off to the target.
OK - both of these individually work! Now the fun part. Am I able to have PHP launch this python program, which sits in the same directory as the php script and pass off four arguments/parameters to it? The arguments/parameters may have spaces in them.
Upvotes: 1
Views: 4423
Reputation: 71414
You will probably want to use exec()
or shell_exec()
to run your python script. Also use escapeshellarg()
and escapeshellcmd()
as appropriate to sanitize your input. This may look like this:
$escaped_cmd = escapeshellcmd('nameofexecutable.exe para1 para2 para3');
exec($escaped_cmd);
Of course you need proper permissions to run the executable.
Upvotes: 1
Reputation: 11734
You're looking for Exec. It will run a command on the console and return the last line of output. If you want all of the output, the optional second argument will give you that.
And as Erty says, sanitize your inputs. DO NOT EVER EVER EVER pass user-supplied data directly to the command line.
Upvotes: 1