黑马程序员技术交流社区

标题: 进程间的通信问题 [打印本页]

作者: 李龙涛    时间: 2011-7-26 23:25
标题: 进程间的通信问题
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 编辑 ]




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2