3

I want to make shell script file in windows and linux with multiple commands inside it.

E.g run.sh and run.bat with the below commands run.bat or run.sh

mvn clean
mvn install
mvn exec:java

When I run my run.bat file it only executes first command mvn clean but it do not execute other commands.

How to make shell-script file with multiple commands so that when I execute it, It executes all commands inside it.

Thanks.

6
  • Check your output (I know maven is verbose and doesn't help), you must have an error coming from the .bat file somewhere. It should be executing the 3 commands sequentially. Commented Jan 31, 2017 at 13:26
  • 1
    Well, the first command could be raising some sort of error as Aaron suggests, but since your script isn't error-checking that shouldn't matter. There's something omitted here, because if you're at a Windows cmd prompt and you run a .bat file it will run all the commands. But, btw, this isn't a case where you need that; you can list multiple goals on a single mvn command line Commented Jan 31, 2017 at 13:28
  • @MarkAdelsberger I was thinking about a .bat syntax error. Now that I think a little more about it, I wouldn't be surprised if missing \r linefeeds would make cmd understand the whole .bat as a single line, so I would check for that Commented Jan 31, 2017 at 13:29
  • Also OP, unless you're still running XP, you could chose powershell's .ps scripts as an alternative to .bat scripts ; their syntax is much closer to .sh files (although they still are two vastly different environnements). I feel like they're still not used a lot in the industry, but if you need some kind of guarantee RedHat started including .ps scripts in their JBoss EAP 7.0 release (although they still include equivalent .bat) Commented Jan 31, 2017 at 13:30
  • 1
    @PrakashPandey have you checked npocmaka's answer? It is likely the solution to your problem. If it is, I still recommend you consider using powershell instead of cmd, I think the problem wouldn't have happened then :) Commented Jan 31, 2017 at 13:38

1 Answer 1

6

mvn is bat file but not binary.

Try with

call mvn clean
call mvn install
call mvn exec:java
Sign up to request clarification or add additional context in comments.

5 Comments

wow... I completely forgot that .bat scripts don't, by default, return to other .bat scripts. Holy 80's batman. Nice catch.
@PrakashPandey - with .sh files you should not have the same problem
yes, it also worked. doing chmod 777 worked. Big thanks
If it is a Windoze Batch Script, why is this post then tagged with bash and linux??????
Oops! You seriously want to write a program which is valid as a bash program AND a Windows Batch program at the same time??? This is weird. It will work only in the simplest cases. Even the solution by npocmaka, which you had accepted, would work as a bash script only, if you define a separate program named call. As soon as some additional logic (conditionals, status code evaluation,...) is added, it will become a nightmare. I suggest to stick to a single language, which is available on both Linux and Windows. If you want to run bash, you can do it on Windows too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.