开发者

Expectj - Getting everything that has been received on the spawn's stdout during this session

I am using Expectj 2.07. I am trying to use getCurrentStandardOutContents() to print everythin开发者_StackOverflowg that has been received on the spawn's 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();
        }


    }

}

But getCurrentStandardOutContents() is not showing anything.

OUTPUT:-

Output->

debraj


You may need to give the subprocess some time to work. Try adding a little bit of delay:

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜