Hassan Baig
Hassan Baig

Reputation: 15834

Calling PHP script from inside a Django project: Could not open input file

I wrote a PHP script that processes some task for me (specifically, encoding videos on a media server). I tested calling this script via python like so:

proc = subprocess.Popen("php vodworkflow_drm_playready_widevine.php videos " +str(video), shell=True, stdout=subprocess.PIPE)

This worked correctly (i.e. the video name passed to the script got correctly encoded and such). However, when I call Popen from inside my Django project, I instead get the output: Could not open input file: my_script.php.

I'm stumped! Can anyone help with what could be going on, and what I can do to rectify this? Thanks, I've been stuck since a while now. Do let me know if you need to see the PHP script and more detailed code.

Upvotes: 0

Views: 871

Answers (1)

CanNuhlar
CanNuhlar

Reputation: 85

Point the php file to php binary by its full path.

proc = subprocess.Popen("php /root/www/bla_bla/vodworkflow_drm_playready_widevine.php videos " +str(video), shell=True, stdout=subprocess.PIPE)

Alternatively, Popen takes an cwd argument. Specify the path to it.

https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module

http://sharats.me/the-ever-useful-and-neat-subprocess-module.html#execute-in-a-different-working-directory

Upvotes: 2

Related Questions