Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Git Bash shell using a python script and then run a shell script in git bash shell

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", 
)
like image 805
tapasd Avatar asked Feb 28 '26 15:02

tapasd


1 Answers

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

like image 140
Abhishek Jain Avatar answered Mar 02 '26 06:03

Abhishek Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!