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

后端 未结 5 1383
挽巷
挽巷 2020-11-30 22:14

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 dou

相关标签:
5条回答
  • 2020-11-30 22:55

    ./clear.bat will do the trick.

    0 讨论(0)
  • 2020-11-30 22:55

    I like start clean, it opens a new window with cmd. This method has some benefits:

    • cmd.exe gets a native console
    • the new console has a native windows character encoding (e.g. cp1251 vs utf8)
    0 讨论(0)
  • 2020-11-30 22:57

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

    cmd "/C clean.bat"
    

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

    0 讨论(0)
  • 2020-11-30 22:59

    At some point, Git for windows added support for the MSYS_NO_PATHCONV environment variable, so in addition to @eckes and @AlikElzin-kilaka solutions, you can also

    MSYS_NO_PATHCONV=1 cmd /c clean.bat
    

    In general, I prefer this solution, as it allows the code to be the closest to resembling normal bash, and there are many ways to export MSYS_NO_PATHCONV depending on your preferred situation.

    Note: Git for Window's bash does not support the MSYS2 environment variable MSYS2_ARG_CONV_EXCL

    The other solutions

    The weird quoting solution

    Why does cmd "/c clean.bat" not create other errors?

    It turns out argument parsing in windows does not follow the same universal rules as it does in *nix. Instead, in windows the arguments are parsed differently based on the runtime you compile against. Basically in windows, the command line arguments are passed in as "one string" and then parsed by the runtime.

    See here for more explanation than you could ever want.

    E.g. cmd parses arguments differently then wscript.exe

    In the end, you can hopefully find something that works with this method, and it is the most "window-esque" of the three solutions

    The // method

    This is pretty well explained here and simple to use, but adds an extra / which does not help readability

    0 讨论(0)
  • 2020-11-30 23:01

    The Git for Windows (msysGit has been superseded by Git for Windows1) FAQ says you have 3 options:

    • Run programs that have problems using the winpty utility. This allows you to keep using the nicer mintty terminal, but can become unwieldy if you need the workaround for many programs.

    • Modify the shortcut for Git Bash to run bash directly without mintty so it uses the default console host and configure it for "Quick Edit", reasonable size and scroll-back and suitable unicode font. You'll still have to live with the other quirks of console host.

    • Install and use ConEmu.

    0 讨论(0)
提交回复
热议问题