在python上运行命令

时间:2016-07-23 02:30:25

标签: python apache python-3.x

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

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)

目前我已经卡在配置部件上 基本上配置行是这样的:

  

/Volumes/nirvash/script/workarea/httpd-2.2.31/configure --prefix = / tmp / apache-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 个答案:

答案 0 :(得分:1)

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

os.chdir(source_location)

或者,您可以在运行configure_command之前使用cdconfigure更改为首次更改目录。

configure_command = 'cd "%s" && %s' % (source_location, configure_command)
相关问题