【发布时间】:2019-01-20 15:02:39
【问题描述】:
我在 Centos 上运行一个 python 脚本,它有一些使用子进程的 bash 命令:
import ConfigParser
import fileinput
import sys
import subprocess
config = ConfigParser.ConfigParser()
config.readfp(open(r'config.file'))
host = config.get('section-1', 'machine_hostname')
##changing the hostname of the machine
change_hostname = "sudo hostnamectl set-hostname new-hostname"
process = subprocess.Popen(change_hostname.split(),
stdout=subprocess.PIPE)
output, error = process.communicate()
我正在从配置文件中导入变量
如何将“new-hostname”作为变量“host”传递给我正在执行的命令,该命令可以从配置文件中动态分配
【问题讨论】:
标签: python bash shell subprocess