Windows 使用python脚本打开Git Bash shell,然后在Git Bash shell中运行shell脚本

Windows 使用python脚本打开Git Bash shell,然后在Git Bash shell中运行shell脚本,windows,git,shell,python-3.6,git-bash,Windows,Git,Shell,Python 3.6,Git Bash,我试图使用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命令提示符运行): 或者,如果执行以

我试图使用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命令提示符运行):

或者,如果执行以下操作,则可以手动运行*.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", 
)

Reason Popen接受参数列表,所以它应该如下所示

import subprocess
p = subprocess.Popen(["C:\Program Files\Git\git-bash.exe","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", 
                     )
使用p.wait()确保脚本成功运行……但是,其他方法可以是将脚本的所有进度捕获到任何记录器文件中,然后检查它是否正在执行它应该执行的操作。。。。。。。
您也可以使用CHECK_输出,因为它返回的返回代码可用于断言脚本是否成功运行……请将其保留在Try-Except-catch中以捕获异常。我可以通过执行以下操作来自动执行此过程。shell脚本位于“C:/Users/userName/Documents/dev”目录中

import subprocess
p = subprocess.Popen("C:\Program Files\Git\git-bash.exe ./shellScriptName.sh 
                 argumentsForShellScript", 
                 bufsize=-1, 
                 executable=None, 
                 stdin=None, 
                 stdout=None, 
                 stderr=None, 
                 preexec_fn=None, 
                 close_fds=False, 
                 shell=False, 
                 cwd="C:/Users/userName/Documents/dev", 
                 )

我不明白答案的来龙去脉。你能详细说明一下吗。
import subprocess
p = subprocess.Popen("C:\Program Files\Git\git-bash.exe ./shellScriptName.sh 
                 argumentsForShellScript", 
                 bufsize=-1, 
                 executable=None, 
                 stdin=None, 
                 stdout=None, 
                 stderr=None, 
                 preexec_fn=None, 
                 close_fds=False, 
                 shell=False, 
                 cwd="C:/Users/userName/Documents/dev", 
                 )