PC Nerd Posted April 11, 2008 Share Posted April 11, 2008 Hi, Ive got a python script that used a file, and I want to build a PHP backend/frontend setup for my site - so that the python script can run on a file upload. Its a similar sort of thing to the onlien doc to pdf converters. The short of it: now to I run a python script, and send it 3 arguments? The longer version of my question: Im not sure how to do this, but I dont really want to have the user waiting for a longer period of time while the python script runs, so Im looking for a way to also run the python script, almost on another thread. I am on a shared host so i night have to live with the delay. basically Ill need to pass teh python script 3 variables, an input filename, an output filename, and a table name (it works with SQL). So - Im not sure exactly how to pass those arguments to python either? EDIT: python is installed on my server, I can manage all teh file writing and upload sort of stuff, its jsut the running of the python script that i dont know how to do. Thanks for any and all help. Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted April 11, 2008 Share Posted April 11, 2008 really depends on the actions of the pl you are running. system("cd /home/bahbah/; nohup ./scripted > /dev/null & echo $!;"); exec() shell_exec() etc tons of ways Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 11, 2008 Author Share Posted April 11, 2008 well its a shared host, so i probably wont be able to do much with the system function, because it looks liek it playing with all the directories on their server. assuming that my script: script.py is in teh same folder/directory that the php is running from, how would I use exec or shell_exec to run the python with arguments also - whats the difference between the two functions that you mentioned? Thanks for the speedy reply Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted April 11, 2008 Share Posted April 11, 2008 try py_eval($code); as in put all your Python Code into the php and use it using that. $code = <<<EOD import php bah bah bah EOD; py_eval($code); Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 11, 2008 Author Share Posted April 11, 2008 so thats basically converting all the python code into php and executing it? - that doesnt seem right? is that what its doing? thanks Quote Link to comment Share on other sites More sharing options...
MiCR0 Posted April 11, 2008 Share Posted April 11, 2008 see http://itrepublic.com/php_information/psecom,id,4,articles,513.html Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 11, 2008 Author Share Posted April 11, 2008 ok. Ive read through that. is it possible to run it directly like a program, instead of rely on importing python into php. i noticed the ARGV or similar in that walkthrough - and i worked out how toget python to receive the arguments, so its just a case of running it. is there a function along the lines of: run(program.exe, args) where args is a dictionary of arguments or somethgin similar? Thanks for all your help. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 11, 2008 Author Share Posted April 11, 2008 ok..... ive been playign with system, and exec and all that - and i cant seem to get it working: <?php exec("myprogram.py"); echo "<br><br><br><br>"; echo "Script executed"; ?> [\CODE] the php doesnt return any errors that cannot find file to run to run or anything - however the myprogram.py is meant to write a file, and its not working at all - its still a completely blank file ( it works when i run in on my ocmpuer not web based) Thanks??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.