0

I am trying to access a function made in PHP in filenamed as php1.php in python3. I saw a post

but Since I don't have enough reputation to comment on that. I am posting my query here.

This is the code I tried here:

import subprocess

subprocess.call(["php", "./php1.php"])
script_response = subprocess.check_output(["php", "./php1.php"])

and getting this error.

Traceback (most recent call last):
  File "test3.py", line 7, in <module>
    subprocess.call(["php", "./php1.php"])
  File "/usr/lib/python3.5/subprocess.py", line 557, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'php'

I think I am missing something basic. Please help me.

john
  • 85
  • 2
  • 10
  • 1
    Try full path to php script_response = subprocess.check_output(["/full/path/to/php", "./php1.php"]) – Rakesh Jan 19 '18 at 12:25
  • What could be the possible path for php is it path to `php` file from root?. I have xxamp installed on my computer. (Sorry my question might be silly) – john Jan 19 '18 at 12:29
  • 1
    `which php` will tell you where your PHP is. – deceze Jan 19 '18 at 12:51
  • @deceze is `which php` a command..? Where do I try it? Because in the Visual code it gives nothing. – john Jan 19 '18 at 12:56
  • It's a command for *NIX command lines. You should clarify what system you're using. – deceze Jan 19 '18 at 12:57

0 Answers0