import java.io.*;
public class TestInOut implements Runnable
{
Process p=null;
public TestInOut()
{
try
{
p=Runtime.getRuntime().exec("java MyTest");
new Thread(this).start();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void send()
{
try
{
OutputStream ops=p.getOutputStream();
while(true)
{
ops.write("help\r\n".getBytes());
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public static void main(String [] args)
{
TestInOut tio=new TestInOut ();
tio.send();
}
public void run()
{
try
{
InputStream in = p.getInputStream();
BufferedReader bfr=new BufferedReader(
new InputStreamReader(in));
while(true)
{
String strLine=bfr.readLine();
System.out.println(strLine);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
class MyTest
{
public static void main(String [] args) throws IOException
{
BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("hi:"+bfr.readLine());
}
}
}
打印出来是hi:help
我想问的是如果是这句代码System.out.println(strLine);的help打印到哪里去了????
[ 本帖最后由 李龙涛 于 2011-07-27 09:56 编辑 ] |
|