发布时间:2019-09-22 08:06:11编辑:auto阅读(2430)
import subprocess
#simple caller, disguard output
subprocess.call("php /path/to/my/old/script.php")
# if you want output
proc = subprocess.Popen("php /path/to/my/script.php", shell=True,
stdout=subprocess.PIPE)
script_response = proc.stdout.read()
方法二:
# shell execute PHP
def php(code):
# open process
p = Popen(['php'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, close_fds=True)
# read output
o = p.communicate(code)[0]
# kill process
try:
os.kill(p.pid, signal.SIGTERM)
except:
pass
# return
return o
To execute a particular file do this:
width = 100
height = 100
code = """<?php
include('/path/to/file.php');
echo start(""" + width + """, """ + height + """);
?>
"""
res = php(code)
上一篇: python 列表遍历方式(含下标)
下一篇: Python 实时向文件写入数据(附代码
47827
46355
37249
34709
29297
25956
24868
19930
19508
17996
5774°
6397°
5908°
5952°
7052°
5896°
5926°
6420°
6386°
7754°