I am trying to open Git Bash shell(C:\Program Files\Git\git-bash.exe) using a python script and then run a shell script(for example, basicSc.sh) in git bash shell. I am running the python script in Windows. How can I do that successfully? Also how can I know the *.sh script is completed from the python script? How can I pass some parameters for the *.sh script from the python script? I am running python 3.6.3.
Python script (running from windows command prompt):
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",
)
Alternatively, if I do the following I can run the *.sh script manually. I am trying to fully automate this. If this is the only possible solution, how do I communicate end of the *.sh script to the python script?
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",
)
use p.wait() to ensure that your script ran successfully.....However other way can be to capture all the progress of script to any logger file then check whether it is doing what it is supposed to do or not....... You can use CHECK_OUTPUT as well because it returns return code which can be used to assert whether your script ran successfully or not....Keep this in Try-Except catch to capture exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With