代码之家  ›  专栏  ›  技术社区  ›  JamesM-SiteGen

python和执行php文件?[复制品]

  •  0
  • JamesM-SiteGen  · 技术社区  · 14 年前

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

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

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

    不工作只返回 0

    2 回复  |  直到 14 年前
        1
  •  2
  •   Rajan    14 年前

    您需要的是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
    
        2
  •  0
  •   Bertolt    14 年前

    如果您在Windows下工作,可以使用 os.startfile() .