expect-it on windows

97 views
Skip to first unread message

anaf...@gmail.com

unread,
Nov 22, 2016, 11:32:56 PM11/22/16
to Yet another Expect for Java
Hi Alex
I am trying to use expect-it on windows using "cmd.exe" shell.
I am able to see the welcome lines from the cmd.exe, run a command using expect.sendline("echo HELLO") and see the echo get executed correctly but the session ends abruptly there although I have other sendline and expect statements after?
I tried cmd, cmd.exe and powershell.exe on windows without success beyond the first line. From what I was reading windows closes the shell after the first command is complete which defeat the purpose of interacting with it.

I am trying to follow the example you provided so my code is as follows:

Process process = Runtime.getRuntime().exec("cmd.exe");
Expect expect = new ExpectBuilder()
.withInputs(process.getInputStream())
.withOutput(process.getOutputStream())
.withTimeout(1, TimeUnit.SECONDS)
.withExceptionOnFailure()
.build();
expect.sendLine("echo HELLO");
expect.sendLine("java -jar ");
String list = expect.expect(regexp("\n$")).getBefore();
System.out.println("List: " + list);


Is there a way to make this to work on windows??

thanks

Ahmad

Alexey Gavrilov

unread,
Dec 2, 2016, 4:25:45 PM12/2/16
to anaf...@gmail.com, Yet another Expect for Java
Hi Ahmad,

I believe the problem is that you don’t always wait for the command prompt when sending commands.
Also you don’s the output from the  'java -jar’ command because it goes to the standard error stream, not stdout.


Hope it helps.

Regards,
Alexey

--
You received this message because you are subscribed to the Google Groups "Yet another Expect for Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-expecti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages