Java Expectj-获取在spawn'上收到的所有信息;在本次会议期间,s stdout
我正在使用Expectj 2.07。我正在尝试使用getCurrentStandardOutContents()打印在spawn的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
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();