从Python测试Apache配置文件

时间:2011-08-31 13:17:15

标签: python apache testing config

我如何从python测试apache配置文件?我尝试使用“os.popen”和“text = stdout_handle.read()”来获得结果,但没有任何反应。

任何帮助都会很棒:)

1 个答案:

答案 0 :(得分:1)

我猜你正试图自动apachectl configtest?你试过subprocess.Popen吗?像下面这样的东西应该让你开始:

from subprocess import Popen, PIPE

args = ['/usr/bin/apachectl','configtest']

result = Popen(args,stdout=PIPE,stderr=PIPE).communicate()
# result[0] will be the standard output, result[1] will be the stderr output

http://docs.python.org/library/subprocess.html#popen-objects

相关问题