如何在 Windows 中的 Cygwin shell 中执行批处理文件

发布于 2024-10-08 03:00:32 字数 611 浏览 0 评论 0原文

我正在尝试通过 Windows 计算机上的 jsp 执行 BATCH 文件,它工作正常,没有任何问题。

然而,DOS 没有与 sed unix 命令等效的命令。因此,我必须安装 cygwin,以便我可以在批处理文件中使用以下 sed 命令。

sed -i "s/<model.version>2.1.1-SNAPSHOT<\/model.version>/<model.version>2.1.1-b-1<\/model.version>/g" pom.xml  

我的问题是如何调用 cygwin shell 以便我的 .bat 文件在 cygwin shell 而不是 Windows 命令提示符中运行。

以下是运行良好的代码片段。唯一的问题是它调用命令提示符。我想调用 cygwin shell 而不是命令提示符。

File dir = new File("C:\\Projects\\release-builds");  
Runtime.getRuntime().exec("cmd.exe /c start build-model.bat", null, dir);  

请指教。

I am trying to execute a BATCH file through through a jsp on a Windows machine and it works fine without any problems.

However DOS does not have an equivalent of sed unix command. Hence I had to install cygwin so that I can use the the following sed command in my batch file.

sed -i "s/<model.version>2.1.1-SNAPSHOT<\/model.version>/<model.version>2.1.1-b-1<\/model.version>/g" pom.xml  

My question is that how can I invoke the cygwin shell so that my .bat file runs within cygwin shell rather than windows command prompt.

Following is the piece of code that works fine. The only problem is that it invokes command prompt. I want to invoke cygwin shell instead of command prompt.

File dir = new File("C:\\Projects\\release-builds");  
Runtime.getRuntime().exec("cmd.exe /c start build-model.bat", null, dir);  

Please advise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七秒鱼° 2024-10-15 03:00:32

您需要将 cygwin 目录添加到您的 PATH 中。 (或服务的路径)然后您可以从 DOS 提示符或 bat 脚本运行 cygwin 命令。

或者您可以提供 c:\cygwin\usr\bin\sed.exe 的完整路径或其他路径。

You need to add the cygwin directory to your PATH. (or the PATH of your service) then you can run cygwin commands from a DOS prompt or bat script.

Or you can give the full path for your c:\cygwin\usr\bin\sed.exe or whatever it is.

递刀给你 2024-10-15 03:00:32

只是从 gnuwin 项目获取 sed 是一种选择吗?然后你就可以将它与本机 Windows shell 一起使用。

Is just getting sed from gnuwin project an option? You could use it with native windows shell then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文