Jump to content

run python script from php ( threadable?)


PC Nerd

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.