Topic: Runtime如何调出cmd的输入输出 ? |
Print this page |
1.Runtime如何调出cmd的输入输出 ? | Copy to clipboard |
Posted by: snooopy Posted on: 2005-09-18 17:30 我知道有个办法可以实现,Runtime.getRuntime().exec("cmd.exe /c dir") 但我想知道如何调出cmd或command的输出和输入啊,让我可以在代码里输入命令编译时会自动运行 ? |
2.Re:Runtime如何调出cmd的输入输出 ? [Re: snooopy] | Copy to clipboard |
Posted by: wild_fox Posted on: 2005-09-23 16:12 Reading Output from a Command try { // Execute command String command = "ls"; Process child = Runtime.getRuntime().exec(command); // Get the input stream and read from it InputStream in = child.getInputStream(); int c; while ((c = in.read()) != -1) { process((char)c); } in.close(); } catch (IOException e) { } |
3.Re:Runtime如何调出cmd的输入输出 ? [Re: snooopy] | Copy to clipboard |
Posted by: wild_fox Posted on: 2005-09-23 16:13 Sending Input to a Command try { // Execute command String command = "cat"; Process child = Runtime.getRuntime().exec(command); // Get output stream to write from it OutputStream out = child.getOutputStream(); out.write("some text".getBytes()); out.close(); } catch (IOException e) { } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |