java - Open Command line + inputs for GUI -
i trying write java gui in netbeans executing program on command line, , have piece of code assigned button
private void jbutton1actionperformed(java.awt.event.actionevent evt) { try { runtime rt = runtime.getruntime(); process pr = rt.exec("open -a /applications/utilities/terminal.app"); bufferedreader input = new bufferedreader(new inputstreamreader(pr.getinputstream())); string line=null; while((line=input.readline()) != null) { system.out.println(line); } int exitval = pr.waitfor(); system.out.println("exited error code "+exitval); } catch(exception e) { system.out.println(e.tostring()); e.printstacktrace(); } } this opens terminal, know how should go inputting commands terminal while still pressing button (ex: "ls", "cd", "javac" etc) thanks!
update: @codebender code looks this.
runtime rt = runtime.getruntime(); process pr = rt.exec("open -a /applications/utilities/terminal.app"); new printstream(pr.getoutputstream).println("ls"); i getting error "cannot find symbol, symbol: variable getoutputstream, location: variable pr of type process" , red line under getoutputstream. ideas?
@codebender should this?
new printstream(pr.getoutputstream{println("ls")});
use can use outputstream write terminal. wrap printstream make things easier.
process pr = rt.exec("open -a /applications/utilities/terminal.app"); printstream ps = new printstream(pr.getoutputstream()); ps.println("ls" + system.lineseparator()); // follow reading of output terminal. if terminal.app default linux terminal, instead of opening new 1 can try,
process pr = rt.exec("ls"); // follow reading of output.
Comments
Post a Comment