关于Process中的getOutputStream

No_what_cant No_what_cant 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
一直不明白 getOutputStream 到底有什么作用

Test test=new Test();
Runtime runtime = Runtime.getRuntime();
Process process=null;
try {
process=runtime.exec("java -version");
InputThread in=test.new InputThread(process);
ErrorInputThread error=test.new ErrorInputThread(process);
in.start();
error.start();
try {
OutputStream stream = process.getOutputStream();
stream.write("ipconfig".getBytes());
stream.flush();
stream.close();
int waitFor = process.waitFor();
process.destroy();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

如果OuputStream是父进程向子进程的输入流的话 那么应该会先执行java -version 然后是ipconfig 命令

如果是子进程的输入流的话 那么我执行
Test test=new Test();
// TODO Auto-generated method stub
Runtime runtime = Runtime.getRuntime();
Process process=null;
try {
process=runtime.exec("notepad.exe");
InputThread in=test.new InputThread(process);
ErrorInputThread error=test.new ErrorInputThread(process);
in.start();
error.start();
try {
OutputStream stream = process.getOutputStream();
stream.write("ipconfig".getBytes());
stream.flush();
stream.close();
int waitFor = process.waitFor();
process.destroy();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

应该文本中有内容

getOutputStream到底有什么作用?
...全文
评论 2
收藏 已收藏
分享
返回顶部
No_what_cant
Java SE 62,620 成员 307,251 内容