You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Program hangs when I try to execute Expect with unexpected string
child, err := gexpect.Spawn("passwd test")
if err != nil {
log.Fatal(err)
}
err = child.Expect("YOU WILL NEVER FIND ME")
if err != nil {
log.Println("should print error", err) // should print error, but it never execute
}
I want to do this because there could be different results for one command. For example, ssh $hostname ls /tmp may output the directory information of tmp directly if the ssh public key has copied to the host, or get the prompt for the password, I found it only works well with non-interactive command.
The text was updated successfully, but these errors were encountered:
I found ExpectTimeout is a way to do this, but it still hangs with child.Wait(), it seems I must use child.Close() to kill the process, here is the modified code:
child, err := gexpect.Spawn("passwd test")
if err != nil {
log.Fatal(err)
}
err = child.ExpectTimeout("YOU WILL NEVER FIND ME", time.Second*1)
if err != nil {
log.Println("should print error", err)
child.Close()
}
child.Wait()
Program hangs when I try to execute Expect with unexpected string
I want to do this because there could be different results for one command. For example,
ssh $hostname ls /tmp
may output the directory information oftmp
directly if the ssh public key has copied to the host, or get the prompt for the password, I found it only works well with non-interactive command.The text was updated successfully, but these errors were encountered: