runtime.exec - java Runtime process - check if waiting for input -
i wish create process using java's runtime: example. process proc = runtime.getruntime().exec("cmd");
then, want somehow wait process until in 'ready input' state, verify has finished of work. anyway on how it?
one thing possible echoing "---finished---" , checking if line written using stdin of process. dislike idea.
is there better (more formal) approach this?
by way, need effect descriobed it. want wait before writing new commands batch file.
thank you.
here couple ideas. hinge on whether or not program you're running expects read , write stdin , stdout.
there's no need wait "ready input" state once you've launched process. if need send commands, use getoutputstream
, write them. if other program still getting ready, data you've written happily sit in buffer until program reads stdin.
using processbuilder
let control arguments , environment. example direct javadocs:
processbuilder pb = new processbuilder("mycommand", "myarg1", "myarg2"); map<string, string> env = pb.environment(); env.put("var1", "myvalue"); env.remove("othervar"); env.put("var2", env.get("var1") + "suffix"); pb.directory(new file("mydir")); process p = pb.start();
then, read or write:
outputstream out = p.getoutputstream(); out.write("some useful data".getbytes()); out.flush();
Comments
Post a Comment