call batch file from cygwin breaks after 1st command?

我只是一个虾纸丫 提交于 2020-01-03 03:43:21

问题


I'm have a "bat" file with some maven commands which are pretty long so I tried to create a single file with MVN commands to execute. I call my bat file in cygwin as:

$./mvncommand.bat

Sample MVN commands in my file:

mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.auditor -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.auditor_1.2.0.jar -Dpackaging=jar -DgeneratePom=false

mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.context -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.context_1.2.0.jar -Dpackaging=jar -DgeneratePom=true

Strangely, only the first mvn install is executed and the all is ok. But how to make Cygwin call the rest of the mvn commands?

Thank you.

JR


回答1:


Maven (mvn) is a batch file and running batch files from another batch file must be done with call.

So change what you have into

call mvn ...

and it should work.

This has nothing to do with Cygwin, by the way.




回答2:


It's possible that your first mvn command is returning an error code. In Windows's cmd, this will cause all subsequent commands to not run. This might be the behavior you want, but you should consider using a *nix-like shell rather than a Windows batch file since you're already using Cygwin.

For example, you could put both commands in a file named mvncommand with your shell of choice.

#!/usr/bin/bash
mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.auditor -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.auditor_1.2.0.jar -Dpackaging=jar -DgeneratePom=false

mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.context -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.context_1.2.0.jar -Dpackaging=jar -DgeneratePom=true


来源:https://stackoverflow.com/questions/4877099/call-batch-file-from-cygwin-breaks-after-1st-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!