From the git console: how do I execute a batch file and then return to the git console?

I have a small script utility called clear.bat that does some homework in my sources.

This is a .bat file so that I can easily double-click it in Windows Explorer.

Sometimes it’s more convenient for me to execute it from my Git bash (msysgit, if that matters).

To do this, enter

 cmd clear.bat exit 

cmd turns my git bash into a normal cmd window where I can easily execute my batch. When I type exit , the cmd environment exits and I return to my Git bash.

Could this be achieved in a simpler way?

I tried cmd /C clean.bat as docs said

 Syntax CMD [charset] [options] CMD [charset] [options] [/c Command] CMD [charset] [options] [/k Command] Options /C Run Command and then terminate /K Run Command and then return to the CMD prompt. This is useful for testing, to examine variables 



Edit:
Just noticed that the message is broken.

I want to execute clean.bat from Git bash without having to enter the three commands above ( cmd , clear.bat , exit ). I just want to execute the .bat file from my git bash. The obvious way would be to create a separate .sh file that does the same job, but this will lead to double code.




Edit 2: When I execute cmd /C clean.bat , Git bash turns into a normal CMD environment and displays only a prompt. The clean.bat file clean.bat not running. This is the same as if I just typed cmd .

Also, adding the /debug switch does literally nothing. It seems that only cmd gets evaluated and all other parameters are ignored.

+47
git windows cmd batch-file
Aug 08 '12 at 13:01
source share
3 answers

After playing a little more, I found a solution myself:

 cmd "/C clean.bat" 

does the trick. But I have no idea why ...

+54
Aug 09 '12 at 6:50
source share

./clear.bat will do the trick.

+21
Apr 16 '16 at 3:16
source share

Git for Windows (msysGit has been replaced with Git for Windows 1 ) The FAQ says that you have 3 options:

  • Launch programs that have problems using the winpty utility. This allows you to use the more convenient mintty terminal, but can become cumbersome if you need a workaround for many programs.

  • Change the shortcut for Git Bash to run bash directly without mintty , so it uses the default console host and configures it for "quick editing", a reasonable size and scroll back and a suitable Unicode font. You still have to live with other quirks of the console host.

  • Install and use ConEmu .

+4
Oct 16 '15 at 12:22
source share



All Articles