windows - 如何在 Windows 上从命令行启动 MingW 控制台 (GitBash)?

标签 windows batch-file command-line git-bash

我正在尝试使用批处理文件自动设置我的工作环境。我无法从命令行启动 MingW64 控制台。

start """%ProgramFiles%\Git\bin\sh.exe"--login 工作正常,但它似乎打开了一个与我正在寻找的不同的 shell 窗口。我将用图片解释这一点。

打开的是一个默认的cmd风格的窗口,集成了bash。这个窗口甚至不能调整大小
enter image description here

我想要的是
enter image description here

我尝试使用命令 start """%ProgramFiles%\Git\git-bash.exe"--login -i -c/bin/bash 但它似乎很快就关闭了打开后的外壳。如果我从资源管理器执行相同的文件,shell 不会自动关闭。

这是我的完整批处理文件以供引用

@echo on

REM start PHP and MYSQL
start "" mysql_server\UniServerZ\UniController.exe start_both

REM Open PhpMyAdmin
start "" http://localhost/us_opt1/

REM Open Folders
start "" %SystemRoot%\explorer.exe "E:\work\"

REM Open Git Bash Instance
:: in order to open the shell in that path
cd E:\work\
:: start "" "%ProgramFiles%\Git\bin\sh.exe" --login
start "" "%ProgramFiles%\Git\git-bash.exe" --login -i -c /bin/bash

REM start sublime text
start "" "E:\Sublime Text Build 3083 x64\sublime_text.exe"

最佳答案

git-bash.exe -i -c "/bin/bash" 似乎工作得更好。
This issue说明了调用 git-bash.exe 的各种其他方法,但得出结论:

Preferred way to run git-for-windows is using git-cmd.exe:

c:\git\git-cmd.exe --command=usr/bin/bash.exe -l -i

然而,这只会在当前 cmd 中打开一个 session ,而 git-bash.exe 会打开一个新窗口。

Combined with this question (打开一个新控制台)和 this one (为了避免出现两个 CMD 窗口),我会使用:

start /b cmd /c git-bash.exe -i -l -c "/bin/bash"

OP Atif Mohammed Ameenuddin报道 in the comments这工作正常:

start "" "%ProgramFiles%\Git\git-bash.exe"

关于windows - 如何在 Windows 上从命令行启动 MingW 控制台 (GitBash)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34252265/

相关文章:

windows - JavaFX ComboBox 在 Windows 10 上没有响应

windows - 如何获取文件或目录的标准化日期/时间戳。在纯批处理脚本中?

mysql - 批处理文件摆脱了输出中的迭代器编号

java - 使用批处理运行 Java + 库

node.js - 如何使用nodejs更改实际的shell cd

C++ 命令行调试参数

command-line - 使用 TestCafe 列出浏览器

python - 如何使用 setuptools 为 windows 命令行安装 python 脚本?

python - Python安装libs文件夹中的python3.lib和python3x.lib有什么区别?

batch-file - 批量.txt阅读器