如何执行php文件,然后查看它的输出?
os.system("php ./index.php")
不起作用只返回0
答案 0 :(得分:2)
你需要的是os.popen函数。它运行该命令并返回该命令输出的stdout管道。您还可以使用os.popen2,popen3
捕获stdin,stderrimport os
outp = os.popen('php ./index.php')
text = outp.read() # this will block until php finishes
# and returns with all output in text
print text
答案 1 :(得分:0)
如果您在Windows下工作,则可以使用os.startfile()。