0

I have the following python script test.py:

import subprocess

subprocess.call(["php", "C:/Documents and Settings/user/My Documents/Downloads/load_data.php"])

the idea is to run another php script in which I make a LOAD DATA INFILE to a MySQL table, but it generates the following error:

Traceback <most recent call last>:
    File "test.py", line 3, in <module>
    subprocess.call<["php","load_data.php"]>
File "C:\Python34\lib\subprocess.py", line 537, in call
   with Popen<*popenargs, **kwargs> as p:
File "C:\Python34\lib\subprocess.py" line 859, in __init__
   restore_signals, start_new_session>
File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child startupinfo>
FileNotFoundError: [WinError 2] The system cannot find the file specified 

If I run the direct load_data.php script in a web browser, it works without any problem so it seems to me that the problem is in python, it is worth mentioning that I have done this correctly before but with python 3.6, some idea if I need it configure something or add a library.

I have php5.3, apache 2.2.21, mysql5.5.20, python3.4, I tried to put the absolute path of the PHP script but is the same

Regards!

5
  • Include the full path to the PHP file Commented Sep 18, 2018 at 0:37
  • still the same :/ Commented Sep 18, 2018 at 0:40
  • And to the executable as well. IIRC subprocess() doesn't call out to the shell, it directly invokes the executable. Therefore it likely isn't searching the PATH for matching executables. Commented Sep 18, 2018 at 0:40
  • @Sammitch subprocess.call(["C:/wamp/bin/php/php5.3.10", "C:/Documents and Settings/user/My Documents/Downloads/load_ctb.php"])? Commented Sep 18, 2018 at 0:43
  • As it works through web,then I think use curl yourdomain/yourphppath.php is better choise Commented Sep 18, 2018 at 0:45

1 Answer 1

1

For run PHP with Python, you must add the full path to the PHP executor and the full path of the file to execute. Example :

import subprocess
subprocess.call(["C:\\wamp64\\bin\\php\\php5.3\\php.exe", "C:\\Documents and Settings\\user\\My Documents\\Downloads\\load_data.php"])

Don't forget to escape the anti-slashes, Otherwise the subprocess will not work and there will be no visible error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.