【发布时间】:2019-08-21 17:12:13
【问题描述】:
我正在尝试使用当前使用 shell 脚本实现的 Python 自动重启应用程序。在运行重启命令之前,我们需要获取一个在 shell 脚本中完成的 .sh 环境文件 . ./opt///**.sh。我正在使用 paramiko 和 exec_command 运行重新启动命令,这会引发库丢失的错误。所以我尝试了几种方法在python程序中获取这个环境文件,但都没有成功。
我尝试过的事情:
stdin1,stdout1,stderr1 = ssh_client1.exec_command("../opt///**.sh")
stdin1,stdout1,stderr1 = ssh_client1.exec_command("source /opt///**.sh")
subprocess.call("/opt///**.sh", shell=True)
os.system("./opt///**.sh")
如果我没记错的话,我从堆栈溢出中选择了以下内容
enter code herecommand = shlex.split("bash -c 'source /opt///**.sh'")enter code hereproc = subprocess.Popen(command, stdout = subprocess.PIPE)enter code herefor proc.stdout 中的行:enter code here(key, _, value) = line.partition("=")enter code hereos.environ[key] = valueenter code hereproc.communicate()
使用 exec_command("/opt///start" )
非常感谢任何帮助。
谢谢。
【问题讨论】:
标签: python-3.7