java - Runtime.exec can't work on JDK 7u25 -
after update java latest version 7u25, runtime.getruntime().exec can't work anymore.
//jhghai_w.filepath = "c:\\aucs\\data\\tmp.txt"; br = new bufferedreader(new inputstreamreader(runtime.getruntime() .exec("cmd.exe /c \"c:\\program files\\juman\\juman.exe \" -e < "+jhghai_w.filepath) .getinputstream()));
i read reference:jdk 7u25: solutions issues caused changes runtime.exec https://blogs.oracle.com/thejavatutorials/entry/changes_to_runtime_exec_problems
and tried modifications below:
br = new bufferedreader(new inputstreamreader(runtime.getruntime() .exec("cmd.exe /c \"c:\\program files\\juman\\juman.exe -e < \""+jhghai_w.filepath) .getinputstream()));
and this:
br = new bufferedreader(new inputstreamreader(runtime.getruntime() .exec(new string[] {"cmd","/c" "c:\\program files\\juman\\juman.exe"-e < ",jhghai_w.filepath}) .getinputstream()));
and this:
br = new bufferedreader(new inputstreamreader(runtime.getruntime() .exec(new string[] {"cmd","/c" "c:\\program files\\juman\\juman.exe","-e“,”<",jhghai_w.filepath}) .getinputstream()));
and this:
br = new bufferedreader(new inputstreamreader(runtime.getruntime() .exec(new string[] {"cmd","/c" "\"c:\\program files\\juman\\juman.exe"","\"-e < \"",jhghai_w.filepath}) .getinputstream()));
i replace "jhghai_w.filepath" "c:\aucs\data\tmp.txt" directly. not working. what's problem in modification?
you should pass command runtime.exec() or processbuilder string-array 3 elements: command first, "/c" second , command executed in cmd third element:
string[] command = new string[3]; command[0] = "cmd.exe"; command[1] = "/c"; command[2] = "\"c:\\program files\\juman\\juman.exe \" -e < "+jhghai_w.filepath; processbuilder pb = new processbuilder(command); pb.start();
see this blogpost section:
the golden rule:
in cases, cmd.exe has 2 arguments: "/c" , command interpretation.
edit: updated solution....
Comments
Post a Comment