java - Command prompt do not close after running batch file which have 'exit' in last line -


i running batch (scanproject.bat) file using java following code

process p= runtime.getruntime().exec("cmd /c start /wait scanproject.bat "+ baseprojdir+"\\"+jo.getstring("name")+" "+st.nexttoken());   system.out.println("exit value : "+p.waitfor()); 

and following batch file code :-

%2: cd %1 ant -f ..\antbuild.xml analyse exit 

batch file run problem command prompt window not closes automatically , hence process not terminated automatically , program wait infinite time complete process.please suggest me technique cmd exit after running ant -f ..\antbuild.xml analyse command.

thanks.

cd /d "full path of directory" or pushd "full path of directory" popd before exit better switch current directory directory on drive (cd , pushd/popd) or network share (just pushd/popd). run in command prompt window cd /? , pushd /? details.

cmd /c starts new windows command process closing process automatically after last command executed. run in command prompt window cmd /? details on options of windows command interpreter.

start command start new windows command process or gui/hybrid application in separate process.

so here starting new windows command process starts new windows command process.

running in command prompt window start /? outputs command. start interprets first double quoted string title string new command process. causes troubles on command lines @ least 1 double quoted string. therefore usage of start requires explicit definition of title string in double quotes first argument start can empty string, i.e. "" first argument after start.

as can read after running exit /? in command prompt window, command without /b exits current windows command process immediately. when ant.exe finished, command process in batch file processed terminated.

i'm having no experience on java development, in point of view should enough use following execution command not need batch file @ all.

the java code line

process p= runtime.getruntime().exec("cmd.exe /c cd /d \"" + jo.getstring("name") + "\" && ant.exe -f ..\\antbuild.xml analyse");  

should enough to

  1. start new windows command process,
  2. set current directory within command process drive , directory specified jo.getstring("name") of course must return directory path drive letter , using backslashes directory separators, , on success
  3. execute ant in directory specified parameters
  4. with terminating windows command process automatically after console application ant.exe finished if ant.exe console application.

i'm not sure if cmd.exe /c needed @ all.

i suggest test command first manually within command prompt window. use in java application if working , producing expected result. , further test if cmd.exe /c needed @ in java code.

see single line multiple commands using windows batch file details operator && run command after previous command successful. , see why not started applications save wanted information in text files expected? explanation of console / gui / hybrid application.

note: there java runtime method exec(string[] cmdarray, string[] envp, file dir) execute command ant.exe parameters -f , ..\antbuild.xml , analyse in directory defined third parameter might better task.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -