从 Windows cmd 调用 MSYS bash
我在 Windows 7 上使用 GCC(使用 TDM 的构建)。我安装了 MSYS 以便能够执行 Make 并使用 makefile 进行编译。然而,每次启动 MSYS Bash shell 时,导航到项目目录并运行make
。
我想要的是自动化这个过程。我更喜欢在 Windows 中拥有一个批处理文件或类似的文件,然后我可以从中调用 MSYS Bash shell。它应该导航到批处理文件所在的目录并调用 make
。
这可能吗?我可以从 cmd 向 MSYS Bash 发送命令(例如导航/调用 make
)吗?或者我可以让 MSYS Bash 运行“Bash 脚本”,它设置要执行的命令,就像批处理脚本一样?
PS:这与 Stack Overflow 问题类似Executing MSYS from cmd.exe with argument。
I'm using GCC on Windows 7 (using the TDM's build). I installed MSYS to be able to execute Make and compile using makefiles. However, it is tedious to every time start up the MSYS Bash shell, navigate to the directory of the project and run make
.
What I want is to automate this process. I prefer to have a batch file in Windows, or something similar, from which I then invoke the MSYS Bash shell. It should navigate to the directory the batch file resides in and call make
.
Is this possible? Can I send commands to MSYS Bash from cmd (like navigation/invoking make
)? Or can I let the MSYS Bash run a "Bash script", which sets the commands to be executed much like batch scripts?
PS: This is something similar to Stack Overflow question Executing MSYS from cmd.exe with arguments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不是 MSYS 专家,但类似的事情对您有用:
Not an MSYS expert, but does something like this work for you:
您不必使用 bash 来执行 make 或任何其他 MSYS 程序。如果将 MSYS bin 目录放在路径中,则可以从 Windows 命令 shell 执行它们。或者,bash shell 内置了非常强大的脚本语言。但我不清楚这是否是您要问的 - 您应该用您想要做什么的实际示例来澄清您的问题,并阐明您想要的步骤自动化。
我自己的设置是有一个名为“Bash here”的 Windows 资源管理器上下文菜单,它会在我选择的目录中打开一个 bash shell。这是通过以下注册表项完成的:
以及 c: 中的以下 bash.cmd 文件:
请注意,MSYS bin 目录位于我的路径上。当然,任何注册表黑客攻击的风险均由您自行承担。
You don't have to use bash to execute make, or any of the other MSYS programs. If you put the MSYS bin directory on your path, you can execute them from a Windows command shell. Alternatively, the bash shell has an enormously powerful scripting language built in. But I'm not clear if that's what you are asking about - you should clarify your question with an actual example of what you want to do, spelling out the steps you want automated.
My own setup is to have a Windows Explorer context menu called "Bash here" which opens a bash shell in the directory I select. This is done via the following registry entries:
And the following bash.cmd file in c::
Note that the MSYS bin directory is on my path. And of course, any registry hacking is at your own risk.
在带有 MSYS 开发人员包的
MSYS-1.0.11
上,我可以使用当前文件夹中的 cmd/bat 文件调用 bash 脚本 (CurrentScript.sh
)命令:On my
MSYS-1.0.11
with the MSYS developers packages, I can call a bash script (CurrentScript.sh
) with a cmd/bat file in the current folder with this command:只需将可执行文件添加到您的 Windows 路径:
请记住,这会向您的路径添加大量可执行文件,这可能会与其他应用程序发生冲突。
..\usr\bin
目录包含所有已安装的 MSYS2 软件包。有很多不必要的东西。..mingw64\bin
目录有一个较小的列表。来源
Just add executables to your Windows PATH:
Keep in mind, this adds a lot of executables to your path which might conflict with other applications. The
..\usr\bin
directory contains all installed MSYS2 packages. There is a lot of unnecessary stuff...mingw64\bin
directory has a smaller list.Source