java command inside batch file is not getting executed when batch file is called from main method -


i calling batch file main method in following way:

public static void main(string args[]){         runtime rt=runtime.getruntime();         try {             process pr=rt.exec("d:\\test1.bat");             pr.waitfor();         } catch (exception e) {             e.printstacktrace();         }     } 

the content of batch file follows:

xcopy d:\a1 d:\a2 call c:\java\jdk1.6.0_27\bin\java.exe -version >log1.txt 2>&1 

upon execution files folder a1 getting copied folder a2, log1.txt not getting generated. if double click batch file, files getting copied , log1.txt getting generated version of java.

  • it log1.txt generated in current working directory of java application, not necessary same directory .bat file.
  • you mention you're using eclipse, sets working directory default, unless you've changed it, top level of project directory containing application entry point (static void main).
  • eclipse not automatically refresh filesystem when external changes made - try selecting project, , file => refresh (f5)

  • there overloaded version of runtime.exec() lets set working directory 3rd parameter..

example

public static void main(string args[]) {     runtime rt = runtime.getruntime();     try {         process pr = rt.exec("d:\\test1.bat", null, new file("d:\\"));         pr.waitfor();     } catch (exception e) {         e.printstacktrace();     } } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -