Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

前端 未结 6 561
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 16:30

I have a batch file that executes three Maven commands, one after the other. Each command can be successfully executed in the script - by itself!. But when I add all three c

相关标签:
6条回答
  • 2020-11-29 16:53

    Maven uses batch files to do its business. With any batch script, you must call another script using the call command so it knows to return back to your script after the called script completes. Try prepending call to all commands.

    Another thing you could try is using the start command which should work similarly.

    0 讨论(0)
  • 2020-11-29 17:01

    To execute more Maven builds from one script you shall use the Windows call function in the following way:

    call mvn install:install-file -DgroupId=gdata -DartifactId=base -Dversion=1.0 -Dfile=gdata-base-1.0.jar  -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=gdata -DartifactId=blogger -Dversion=2.0 -Dfile=gdata-blogger-2.0.jar  -Dpackaging=jar -DgeneratePom=true
    call mvn install:install-file -DgroupId=gdata -DartifactId=blogger-meta -Dversion=2.0 -Dfile=gdata-blogger-meta-2.0.jar  -Dpackaging=jar -DgeneratePom=true
    
    0 讨论(0)
  • 2020-11-29 17:01

    Dos commands in my batch file were running only when I type EXIT in command/DOS window. This problem solved when I removed CMD from batch file. No need of it.

    0 讨论(0)
  • 2020-11-29 17:09

    Try writing the following batch file and executing it:

    Echo one
    cmd
    Echo two
    cmd
    Echo three
    cmd
    

    Only the first two lines get executed. But if you type "exit" at the command prompt, the next two lines are processed. It's a shell loading another.

    To be sure that this is not what is happening in your script, just type "exit" when the first command ends.

    HTH!

    0 讨论(0)
  • 2020-11-29 17:16

    Having call helps. However today it didn't.

    This is how I solved it:

    Bat file contents (if you want to stop batch when one of cmds errors)

    cmd1 && ^
    cmd2 && ^
    cmd3 && ^
    cmd4
    

    Bat file contents (if you want to continue batch when one of cmds errors)

    cmd1 & ^
    cmd2 & ^
    cmd3 & ^
    cmd4
    
    0 讨论(0)
  • 2020-11-29 17:16

    It should be that the particular mvn command execs and does not return, thereby not executing the rest of the commands.

    0 讨论(0)
提交回复
热议问题