Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Expectj-获取在spawn'上收到的所有信息;在本次会议期间,s stdout_Java_Linux_Expect - Fatal编程技术网

Java Expectj-获取在spawn'上收到的所有信息;在本次会议期间,s stdout

Java Expectj-获取在spawn'上收到的所有信息;在本次会议期间,s stdout,java,linux,expect,Java,Linux,Expect,我正在使用Expectj 2.07。我正在尝试使用getCurrentStandardOutContents()打印在spawn的stdout上收到的所有内容 public class ExpectTest { public static void main(String args[]) { ExpectJ expectInit = new ExpectJ(5); try { Spawn s = expec

我正在使用Expectj 2.07。我正在尝试使用getCurrentStandardOutContents()打印在spawn的stdout上收到的所有内容

public class ExpectTest {

    public static void main(String args[])
    {
        ExpectJ expectInit = new ExpectJ(5);
        try
        {
            Spawn s = expectInit.spawn("/bin/sh");           
            s.send("echo debraj\n");            
            System.out.println("Output->"+s.getCurrentStandardOutContents());
            s.expectClose();

        }catch(Exception io)
        {
            io.printStackTrace();
        }


    }

}
但是getCurrentStandardOutContents()没有显示任何内容

输出:-

Output-> 输出->
debraj

您可能需要给子流程一些时间来工作。尝试添加一点延迟:

Spawn s = expectInit.spawn("/bin/sh");           
s.send("echo debraj\n");

Thread.sleep(200);                      // Pause for 0.2s

System.out.println("Output->"+s.getCurrentStandardOutContents());
s.expectClose();