Python和执行php文件?

时间:2010-10-01 08:34:36

标签: php python

  

可能重复:
  Start local PHP script w/ local Python script

如何执行php文件,然后查看它的输出?

os.system("php ./index.php")

不起作用只返回0

2 个答案:

答案 0 :(得分:2)

你需要的是os.popen函数。它运行该命令并返回该命令输出的stdout管道。您还可以使用os.popen2,popen3

捕获stdin,stderr
import 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()