Wednesday, 15 June 2011

Calling a batch from java requires to be started from the current batch file folder -


I am starting a batch file from my java program which will block some tokkat, the batch works only if it It will start from the command line but it does not work from starting Java, the problem is that the batch should not be called from the folder where it was continued continuously. So some files can not be found, my question is how can I switch to the folder where the batch is false and then start the batch so that it is running from its folder and get the required files < P> My code in batch folder c: \ foobar \ mybatch.cmd

for example is how the batch will be called by Java at present

  Public Zero Startbatch ( Path batch path) {if (batch path == empty) {new invalid records uppercase Throw ("Batch can not be started without path"); } If (! Files.exists (batchpath)) (new invalid unmatched findings ("batch is not present" + batch path. String ()); try {log.info ("batch initial" + batchpath.absolute path () ToString (); String command = "CMD.axa / c" + batchpath.assolute path () .tostring (); Process P; P = Runtime.getRuntime () .exec (command); p.waitFor (); Buffer Reader = New buffed reader (neweststream reader (PJet InputStream ()); String Line = Reader. Adlline (); while (line! = Null) {log.info (line); line = reader.readline ();}} grip (IOException e) {// TODO auto-generated cal block e.printStackTrace ();} Grip (Interrupted ejection) {// TODO auto-generated cache block e.printStackTrace ();} // Tudo auto generated method stub}    

You just cd: \ foobar \ in the batch file.

No comments:

Post a Comment