Skip to content

Instantly share code, notes, and snippets.

@yifan-gu
Last active November 17, 2015 21:30
Show Gist options
  • Save yifan-gu/8fbca091d72f31f55e6d to your computer and use it in GitHub Desktop.
Save yifan-gu/8fbca091d72f31f55e6d to your computer and use it in GitHub Desktop.
gexpect collect
package main
import (
"fmt"
"github.com/steveeJ/gexpect"
)
func main() {
hey := "testoutput"
child, err := gexpect.Command(hey)
if err != nil {
panic(err)
}
if err := child.Start(); err != nil {
panic(err)
}
child.Capture()
if err := child.Wait(); err != nil {
fmt.Println(err)
}
// If uncomment this line, then I can see "print stdout something", but not "print stderr something".
//if err := child.Expect("print stdout"); err != nil {
// fmt.Println(err)
//}
// If uncomment this line, then I can see both lines.
//if err := child.Expect("print stderr"); err != nil {
// fmt.Println(err)
//}
fmt.Println("child collect result:", string(child.Collect()))
}
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("print stdout something")
fmt.Fprintln(os.Stderr, "print stderr something")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment