-7

I want to execute php commands using a python code. So also I wanted to know how to use php commands in command line

1 Answers1

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

How to access PHP with the Command Line on Windows?

Community
  • 1
  • 1
hoangvu68
  • 845
  • 2
  • 13
  • 28