0

I am using Expectj 2.07. I am trying to use getCurrentStandardOutContents() to print everything 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

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
tuk
  • 5,941
  • 14
  • 79
  • 162

1 Answers1

1

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();
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215