Java IOException When Trying to Run a Bat File in Another Directory -


i'm using apache commons exec run bat file in specified directory.

file file = new file("c:\\users\\aaron\\documents\\minecraftforge\\forge\\mcp");     for(string s : file.list())     {         if(s.equals("recompile.bat"))         {             defaultexecutor executor = new defaultexecutor();             executor.setworkingdirectory(file);             commandline commandline = new commandline("recompile.bat");              try             {                 executor.execute(commandline);             } catch (executeexception e)             {                 e.printstacktrace();             } catch (ioexception e)             {                 e.printstacktrace();             }         }     } 

the code try run bat file if can find file i'm looking for, code comes with

java.io.ioexception: cannot run program "recompile.bat" (in directory "c:\users\aaron\documents\minecraftforge\forge\mcp"): createprocess error=2, system cannot find file specified     @ java.lang.processbuilder.start(unknown source)     @ java.lang.runtime.exec(unknown source)     @ org.apache.commons.exec.launcher.java13commandlauncher.exec(java13commandlauncher.java:58)     @ org.apache.commons.exec.defaultexecutor.launch(defaultexecutor.java:254)     @ org.apache.commons.exec.defaultexecutor.executeinternal(defaultexecutor.java:319)     @ org.apache.commons.exec.defaultexecutor.execute(defaultexecutor.java:160)     @ org.apache.commons.exec.defaultexecutor.execute(defaultexecutor.java:147)     @ mod.learncraft.packer.packager.<init>(packager.java:24)     @ mod.learncraft.packer.packager.main(packager.java:38) caused by: java.io.ioexception: createprocess error=2, system cannot find file specified     @ java.lang.processimpl.create(native method)     @ java.lang.processimpl.<init>(unknown source)     @ java.lang.processimpl.start(unknown source)     ... 9 more ` 

this makes no sense me, since seems file name lines file in directory, process builder can't find it.

the problem that, not running program "c:\users\aaron\documents\minecraftforge\forge\mcp" thats y commandline not able find file specified argument. should try passing absolute path

or, modify code bit:

file file = new file("c:\\users\\aaron\\documents\\minecraftforge\\forge\\mcp");     for(file s : file.listfiles())     {         if(s.getname().equals("recompile.bat"))         {             defaultexecutor executor = new defaultexecutor();             executor.setworkingdirectory(file);             commandline commandline = new commandline(s.getabsolutepath());              try          {             executor.execute(commandline);         } catch (executeexception e)         {             e.printstacktrace();         } catch (ioexception e)         {             e.printstacktrace();         }     } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -