I want to execute php commands using a python code. So also I wanted to know how to use php commands in command line
Asked
Active
Viewed 1,223 times
-7
-
What you have tried so far ? – Nishant Nawarkhede Apr 17 '14 at 06:34
-
ya but I couldn't find anything – user3544059 Apr 17 '14 at 06:37
-
What do you mean by php Commands ? or you want to run php script ? – Nishant Nawarkhede Apr 17 '14 at 06:39
-
Please split this up into 1 questions in future. This will help you to get better answers. – frlan Apr 17 '14 at 06:54
-
This should have been two separate questions (and I bet they're both duplicates). – Mark Amery Jun 08 '14 at 16:44
1 Answers
3
With python
import subprocess
# if the script don't need output.
subprocess.call("php /path/to/your/script.php")
# if you want output
proc = subprocess.Popen("php /path/to/your/script.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()
With console
php -r "echo 'a';"
Or
php "path\to\php\file";
If you are using windows, you need add php folder to PATH. View tutorial at here
-
-
You can run php script from python by using subprocess.Popen function. That is same function exec in php. – hoangvu68 Apr 17 '14 at 08:26
-
-
I had tried the code you have posted above but that's giving an error – user3544059 Apr 17 '14 at 08:29
-
1
-
-
-
-
but anyway please try subprocess.call(["php", "path/to/script.php"]); – hoangvu68 Apr 17 '14 at 08:42
-
-
you are using linux or windows? Example Linux: /var/www/script.php Windows: C:\\htdocs\\www\\script.php – hoangvu68 Apr 17 '14 at 08:47
-
I am using windows my script name is omsha.php that script is stored in c drive then xampp then htdocs then a folder DONE in the folder DONE there is the script named omsha.php Pls tell the entire format to write – user3544059 Apr 17 '14 at 08:52
-
import subprocess subprocess.call("php C:\\xampp\\htdocs\\DONE\\omsha.php") – hoangvu68 Apr 17 '14 at 08:59