Monday 15 September 2014

Java- Runtime.getRuntime().exec() will not execute python.exe -



Java- Runtime.getRuntime().exec() will not execute python.exe -

for project need start python.exe via runtime.getruntime.exec(). however, when seek run it won't execute, doesn't throw ioexception. here's code:

try { process process=runtime.getruntime().exec("c:\\program files (x86)\\pythontest\\python.exe"); } grab (ioexception e) { system.out.println("cannot find python.exe"); e.printstacktrace(); }

you need output process , (waitfor() finish). like,

final string cmd = "c:/program files (x86)/pythontest/python.exe"; process p = runtime.getruntime().exec(cmd); final inputstream = p.getinputstream(); thread t = new thread(new runnable() { public void run() { inputstreamreader isr = new inputstreamreader(is); int ch; seek { while ((ch = isr.read()) != -1) { system.out.print((char) ch); } } grab (ioexception e) { e.printstacktrace(); } } }); t.start(); p.waitfor(); t.join();

to python you'll want outputstream.

java runtime

No comments:

Post a Comment