从Windows cmd调用MSYS bash

时间:2021-03-05 06:27:00

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.

我在Windows 7上使用GCC(使用TDM的构建)。我安装了MSYS,可以使用makefile执行Make和compile。但是,每次启动MSYS Bash shell,导航到项目目录并运行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.

我想要的是自动化这个过程。我更喜欢在Windows中有一个批处理文件,或类似的东西,然后从中调用MSYS Bash shell。它应该导航到批处理文件所在的目录并调用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?

这可能吗?我可以从cmd向MSYS Bash发送命令(如导航/调用make)吗?或者我可以让MSYS Bash运行“Bash脚本”,它将命令设置为像批处理脚本一样执行?

PS: This is something similar to Stack Overflow question Executing MSYS from cmd.exe with arguments.

PS:这类似于Stack Overflow问题从带有参数的cmd.exe执行MSYS。

3 个解决方案

#1


10  

Not an MSYS expert, but does something like this work for you:

不是MSYS专家,但做这样的事情对你有用:

rem Call this something like compile-project.bat
c:
cd \src\project
bash -c "make"

#2


7  

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.

您不必使用bash来执行make或任何其他MSYS程序。如果将MSYS bin目录放在路径上,则可以从Windows命令shell执行它们。或者,bash shell内置了一个非常强大的脚本语言。但是我不清楚这是不是你要问的问题 - 你应该用你想要做的实际例子说明你的问题,拼出你想要的步骤自动化。

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:

我自己的设置是有一个名为“Bash here”的Windows资源管理器上下文菜单,它在我选择的目录中打开一个bash shell。这是通过以下注册表项完成的:

[HKEY_CLASSES_ROOT\Directory\shell\mybash]
@="Bash Here"

[HKEY_CLASSES_ROOT\Directory\shell\mybash\command]
@="cmd /c c:\\bash.cmd %1"

And the following bash.cmd file in c::

以及c ::中的以下bash.cmd文件

@echo off
title bash
cd %1%
bash

Note that the MSYS bin directory is on my path. And of course, any registry hacking is at your own risk.

请注意,MSYS bin目录位于我的路径上。当然,任何注册表黑客攻击都需要您自担风险。

#3


0  

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:

在带有MSYS开发人员包的MSYS-1.0.11上,我可以使用以下命令在当前文件夹中使用cmd / bat文件调用bash脚本(CurrentScript.sh):

R:\MinGW\MSYS-1.0.11\bin\sh "%cd%\CurrentScript.sh"

#1


10  

Not an MSYS expert, but does something like this work for you:

不是MSYS专家,但做这样的事情对你有用:

rem Call this something like compile-project.bat
c:
cd \src\project
bash -c "make"

#2


7  

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.

您不必使用bash来执行make或任何其他MSYS程序。如果将MSYS bin目录放在路径上,则可以从Windows命令shell执行它们。或者,bash shell内置了一个非常强大的脚本语言。但是我不清楚这是不是你要问的问题 - 你应该用你想要做的实际例子说明你的问题,拼出你想要的步骤自动化。

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:

我自己的设置是有一个名为“Bash here”的Windows资源管理器上下文菜单,它在我选择的目录中打开一个bash shell。这是通过以下注册表项完成的:

[HKEY_CLASSES_ROOT\Directory\shell\mybash]
@="Bash Here"

[HKEY_CLASSES_ROOT\Directory\shell\mybash\command]
@="cmd /c c:\\bash.cmd %1"

And the following bash.cmd file in c::

以及c ::中的以下bash.cmd文件

@echo off
title bash
cd %1%
bash

Note that the MSYS bin directory is on my path. And of course, any registry hacking is at your own risk.

请注意,MSYS bin目录位于我的路径上。当然,任何注册表黑客攻击都需要您自担风险。

#3


0  

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:

在带有MSYS开发人员包的MSYS-1.0.11上,我可以使用以下命令在当前文件夹中使用cmd / bat文件调用bash脚本(CurrentScript.sh):

R:\MinGW\MSYS-1.0.11\bin\sh "%cd%\CurrentScript.sh"