Sunday 15 September 2013

java - running simple cmd.exe commands with apache commons exec -



java - running simple cmd.exe commands with apache commons exec -

i want run cmd.exe commands java (for illustration md c:\blabla create new directory c:\blabla ) code looks , runs without errors:

import java.io.ioexception; import org.apache.commons.exec.commandline; import org.apache.commons.exec.defaultexecutor; import org.apache.commons.exec.executeexception; public class test { public static void main(string[] args) throws executeexception, ioexception { commandline cmdline = new commandline("cmd.exe"); cmdline.addargument("md"); cmdline.addargument("c:\\blabla"); defaultexecutor executor = new defaultexecutor(); executor.execute(cmdline); } }

but if go c:\ there no folder blabla expect, since manually typing md c:\blabla in cmd.exe works fine. tried "c:\windows\system32\cmd.exe" instead of "cmd.exe" no use.

the output in console looks this:

microsoft windows [version 6.1.7601] copyright (c) 2009 microsoft corporation. rights reserved.

c:\users\selphiron\workspace\test>

where mistake?

the error command itself. seek did in command line.

your code passes "cmd.exe md c:\blabla" system. starts new shell. passing shell command cmd.exe doesnt trick. seek utilize

cmd /c md c:\blabla

the /c makes difference here.

java apache cmd apache-commons-exec

No comments:

Post a Comment