java execute cmd file fails -


i writing java program executes cmd-file @ point. both in same directory.

i using processbuilder, since more flexible. when run code fails:

string current_directory = system.getproperty("user.dir");   processbuilder builder=new processbuilder(current_directory+"\\"+ "mycmdfile.cmd");  builder.directory(new file(current_directory));  file log = new file("log.txt");  builder.redirecterrorstream(true);  builder.redirectoutput(redirect.appendto(log));  process process=builder.start();  process.waitfor();  system.out.println("cmd file executed"); 

i exception:

java.io.ioexception: cannot run program "c:\test\mycmdfile.cmd" (in directory "c:\test"): no such file or directory     @ java.lang.processbuilder.start(unknown source)     @ org.java.test.executecmdfile(mymainclass.java:189)     @ org.java.test.main(mymainclass.java:70) caused by: java.io.ioexception: no such file or directory        @ java.lang.processimpl.openforatomicappend(native method)     @ java.lang.processimpl.newfileoutputstream(unknown source)     @ java.lang.processimpl.start(unknown source)     ... 3 more 

however, when comment out these lines works:

  processbuilder builder=new processbuilder(current_directory+"\\"+    "mycmdfile.cmd");     //builder.directory(new file(current_directory));     //file log = new file("log.txt");     // builder.redirecterrorstream(true);     // builder.redirectoutput(redirect.appendto(log));     process process=builder.start();     process.waitfor();     system.out.println("cmd file executed"); 

i need these lines, since want have log messages.

i found error...it stupid one..this code works:

string current_directory = system.getproperty("user.dir");   processbuilder builder=new processbuilder(current_directory+"\\"+ "mycmdfile.cmd");  builder.directory(new file(current_directory));  file log = new file("log.txt");  builder.redirecterrorstream(true);  builder.redirectoutput(redirect.appendto(log));  process process=builder.start();  process.waitfor();  system.out.println("cmd file executed"); 

the problem line:

 file log = new file("log.txt"); 

in production environment long path (which wrong), demonstration purposes changed it, before posted question here. thought problem connected cmd-file exception told me whole time...now after gave correct path log-file works..thx everyone


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -