在 Windows 命令行中自动化 cygwin 命令(最终在 MsBuild 中)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2053764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:44:29  来源:igfitidea点击:

Automating cygwin commands in windows command line (and ultimately in MsBuild)

windowscommand-linemsbuildcygwin

提问by BeraCim

I have a situation where I have a few cygwin commands which I wish to be run in Windows command line e.g.

我有一种情况,我有几个 cygwin 命令,我希望在 Windows 命令行中运行,例如

chmod 777 /home/administrator/*

Currently I have to manually type in cygwin.bat, then enter the above command in cygwin. I was wondering whether it is possible (and if so, how) to have these steps automated in Windows command line?

目前我必须手动输入cygwin.bat,然后在cygwin中输入上述命令。我想知道是否有可能(如果有,如何)在 Windows 命令行中自动执行这些步骤?

Ultimately I want all of the above commands to be in MsBuild to achieve full automation if possible.

最终,如果可能的话,我希望上述所有命令都在 MsBuild 中以实现完全自动化。

Thanks.

谢谢。

回答by omermuhammed

One way to do this is to launch windows command prompt from a batch file, then, in there, call the shell script which has the command that you want to run.

一种方法是从批处理文件启动 Windows 命令提示符,然后在那里调用包含您要运行的命令的 shell 脚本。

batchfile-for-cygwin.bat will contain

batchfile-for-cygwin.bat 将包含

@echo off
C:\cygwin\bin\bash -li /cygdrive/c/<path-to-shell-script-location>/chmod-cmd.sh

And then, in chmod-cmd.sh you can just have the command.

然后,在 chmod-cmd.sh 中,您可以拥有该命令。

chmod 777 /home/administrator/*

With this kind of setup, you can use it in MSBuild too, I should think. I use it in Ant scripts and it works for me.

通过这种设置,您也可以在 MSBuild 中使用它,我想。我在 Ant 脚本中使用它,它对我有用。