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.
You will probably want to use
exec()orshell_exec()to run your python script. Also useescapeshellarg()andescapeshellcmd()as appropriate to sanitize your input. This may look like this:Of course you need proper permissions to run the executable.