Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of a git console: how do I execute a batch file and then return to git console?

I have a small utility script called clear.bat that does some housekeeping work on my sources.

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

Sometimes, I find it more handy to execute it from my Git bash (msysgit, if this matters).

To do this, I type

cmd clear.bat exit 

cmd turns my Git bash into a normal cmd window where I could easily execute my batch. When I type exit, the cmd environment is terminated and I'm back in my Git bash.

Could this be achieved in an easier way?

I tried cmd /C clean.bat since the docs say

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 post is broken.

What I want is to execute clean.bat from within the Git bash without having to type the three commands above (cmd, clear.bat, exit). I just want to execute the .bat file from within my Git bash. Obvious way would be to create a separate .sh file that does the same work but this will lead to double code.


Edit 2: When I execute cmd /C clean.bat, the Git bash turns into a plain CMD environment and only displays the prompt. The file clean.bat does not get executed. It's the same as if I just type cmd.

Also, adding a /debug switch does literally nothing. Seems like only cmd gets evaluated and all further parameters are getting ignored.

like image 305
eckes Avatar asked Aug 08 '12 13:08

eckes


People also ask

How do I run a batch file from the console application?

Process. Start("c:\\batchfilename. bat"); this simple line will execute the batch file.

How do I keep the console open after executing a batch file?

Edit your bat file by right clicking on it and select “Edit” from the list. Your file will open in notepad. Now add “PAUSE” word at the end of your bat file. This will keep the Command Prompt window open until you do not press any key.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.


1 Answers

After playing around a bit more, I found the solution myself:

cmd "/C clean.bat" 

does the trick. But I got no clue, why...

like image 72
eckes Avatar answered Oct 13 '22 05:10

eckes