运行 来自 Python 脚本的 .sh 文件?

Running .sh file from Python script?

我在 Oracle Linux 6.8 中使用我开发的 python 脚本 运行 设置 .sh 脚本时遇到问题。我已经在 Windows OS 中开发了这些脚本并且它们 运行 没有问题,现在我正在尝试将这些脚本修改为 运行 它们在 Linux 但是我遇到了问题,因为我不熟悉 Linux OS。

我 运行 在 Windows 中使用 python 中的 Popen 命令创建了一个 .bat 文件,例如: p = Popen("StartScript.bat", cwd=r"My path")

其中StartScript.bat.bat文件,My Path.bat文件所在路径。这在 Windows OS 中非常有效,但是如果我想 运行 StartScript.sh,我如何对 Linux OS 做同样的事情文件。

execute a shell-script from Python subprocess

How to execute a shell script through python

请看一下这两个线程。希望对你有帮助。

使用这一行:

import os
os.popen('sh command')

例如

import os
os.popen('sh /home/oracle/scripts/start.sh')

享受