2016-07-23 96 views
0

我想创建一个脚本来自动编译Apache。可悲的是,在我的工作中,我需要编译每个安装的apache。
所以,我想出了这个小代码来运行一个命令:python上运行命令

print("Source location %s" % source_location) 
print("Configure command %s" % configure_command) 
config = subprocess.Popen(configure_command, stdout=subprocess.PIPE, shell=True) 
(output, err) = config.communicate() 
config_status = config.wait() 
print("Return configure status = %s" % config_status) 

目前我卡上的配置部分。
基本上configure行是这样的:

/Volumes/nirvash/script/workarea/httpd-2.2.31/configure前缀=/TMP /阿帕奇-2.2.31-INSTANCE1 --enable- mods-shared = all --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-deflate --enable-cache --enable-disk-cache - enable-mem-cache --enable-file-cache --with-included-apr --with-mpm = worker

问题是,当apache编译时,它会创建(mkdir)“include “目录里面的httpd-2.2.31。但在这种情况下,该目录是在我的脚本的bin目录中创建的。
因此,脚本正在运行时创建目录。

可以解决这个问题吗?有没有办法在编译的目录中运行configure?

回答

1

您可以使用os.chdir将脚本的当前目录更改为包含源代码的目录。

os.chdir(source_location) 

另外,还可以使用cd运行configure之前更改configure_command先更改目录。

configure_command = 'cd "%s" && %s' % (source_location, configure_command)