Java 等待另一进程的响应

Java 等待另一进程的响应,java,multithreading,server,command-line-interface,Java,Multithreading,Server,Command Line Interface,因此,为了缩短时间,我正在构建一个脚本来控制一个PHP服务器(针对Laravel)。到目前为止,这一切都很好 public void run() { //All the variables I'm about to initialize above synchronized (this) are dummy //variables, just so you know what they are. Their real location are the base //cla

因此,为了缩短时间,我正在构建一个脚本来控制一个PHP服务器(针对Laravel)。到目前为止,这一切都很好

public void run()
{
    //All the variables I'm about to initialize above synchronized (this) are dummy
    //variables, just so you know what they are. Their real location are the base
    //class.
        Process process = null;
        int port = 8888;
        String path = "C:/xampp/htdocs/some-laravel-server/public";
        boolean on = true;
    synchronized (this) 
    {
        //Turning on the server
        try {
            process = Runtime.getRuntime().exec("php -S localhost:" + port + " -t " + path);
            System.out.println("Server running on localhost:" + port);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        
        //Waiting until another method (which switches var 'on' to false) to notify();
        while(on && process != null)
        {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        
        //Turning off the server
        process.destroy();
        System.out.println("Server stopped");
        
        //resetting
        on = true;
        process = null;
    }
}
现在这个
进程
是一个PHP
CLI
进程。无论何时有人真正连接到服务器,它都会发送一些关于用户/连接的消息。我的问题是,我可以用
process
打开另一个线程吗?基本上,每当
CLI
实际发送内容时,它会给我一个字符串(我可以稍后使用)

例如:

当用户连接到服务器时,CLI将响应:

[2015年11月23日星期一22:00:00]::1:1234[302]:/

[2015年11月23日星期一22:00:01]::1:1234[200]:/somepage

现在我可以在Java程序中以某种方式获得这两个字符串(使用Process对象或其他方法)


谢谢

使用
ProcessBuilder
以。。。也可以查看ProcessBuilder的javadoc。重定向。@fge好的,我会的,谢谢!使用
ProcessBuilder
以。。。也可以查看ProcessBuilder的javadoc。重定向。@fge好的,我会的,谢谢!