Execute php code in Python

后端 未结 5 2080
时光取名叫无心
时光取名叫无心 2020-11-27 16:30

For some reason, I have to run a php script to get an image from Python. Because the php script is very big and it is not mine, it will takes me days to find out the right a

5条回答
  •  醉梦人生
    2020-11-27 17:12

    Example code:

    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()
    

提交回复
热议问题