Last active
November 17, 2015 21:30
-
-
Save yifan-gu/8fbca091d72f31f55e6d to your computer and use it in GitHub Desktop.
gexpect collect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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