【发布时间】:2018-04-17 06:41:37
【问题描述】:
我正在尝试使用 python 脚本打开 Git Bash shell(C:\Program Files\Git\git-bash.exe),然后在 git bash shell 中运行 shell 脚本(例如 basicSc.sh)。我在 Windows 中运行 python 脚本。我怎样才能成功地做到这一点?另外我怎么知道 *.sh 脚本是从 python 脚本完成的?如何从 python 脚本传递 *.sh 脚本的一些参数?我正在运行 python 3.6.3。
Python 脚本(从 Windows 命令提示符运行):
import subprocess
p = subprocess.Popen
(
"C:\Program Files\Git\git-bash.exe --l -- C:/Users/userName/Documents/dev/basicSc.sh",
bufsize=-1,
executable=None,
stdin=None,
stdout=None,
stderr=None,
preexec_fn=None,
close_fds=True,
shell=False,
cwd="C:/Users/userName/Documents/dev",
)
或者,如果我执行以下操作,我可以手动运行 *.sh 脚本。我正在尝试完全自动化。如果这是唯一可能的解决方案,我如何将 *.sh 脚本的结尾传达给 python 脚本?
import subprocess
p = subprocess.Popen("C:\Program Files\Git\git-bash.exe",
bufsize=-1,
executable=None,
stdin=None,
stdout=None,
stderr=None,
preexec_fn=None,
close_fds=True,
shell=False,
cwd="C:/Users/userName/Documents/dev",
)
【问题讨论】:
标签: windows git shell python-3.6 git-bash