public class ReadStandered { public static void main(String[] args) {
System.out.println("hello world!"); }
}
public class WriteToProcess {
public static void main(String[] args) throws Exception {
PrintStream ps = null;
BufferedReader br = null;
Process p = null; p = Runtime.getRuntime().exec("java ReadStandard");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String buff = null;
while((buff=br.readLine())!=null){
System.out.println(buff);
}
br.close();
}
}
System.out.println("hello world!"); }
}
public class WriteToProcess {
public static void main(String[] args) throws Exception {
PrintStream ps = null;
BufferedReader br = null;
Process p = null; p = Runtime.getRuntime().exec("java ReadStandard");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String buff = null;
while((buff=br.readLine())!=null){
System.out.println(buff);
}
br.close();
}
}
String ret = "I am your son";
//返回消息给父程序
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(ret) ;
bw.flush();
bw.close(); }
可还是阻塞,父进程读不到数据
2. 修改类名后如果还是有错,先打印p.getErrorStream()的内容就可以知道问题出在哪快