Last active
October 13, 2015 02:31
-
-
Save keithpitt/22766a0d3c523e5563e7 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"bytes" | |
"fmt" | |
"io" | |
"os" | |
"os/exec" | |
"path" | |
"sync" | |
"syscall" | |
"github.com/kr/pty" | |
) | |
func main() { | |
wd, _ := os.Getwd() | |
c := exec.Command(path.Join(wd, "pty-test.sh")) | |
c.Dir = wd | |
c.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} | |
f, err := pty.Start(c) | |
if err != nil { | |
panic(err) | |
} | |
var wg sync.WaitGroup | |
wg.Add(1) | |
var buffer bytes.Buffer | |
go func() { | |
_, err = io.Copy(&buffer, f) | |
if e, ok := err.(*os.PathError); ok && e.Err == syscall.EIO { | |
// We can safely ignore this error, because it's just | |
// the PTY telling us that it closed successfully. See: | |
// https://github.com/buildkite/agent/pull/34#issuecomment-46080419 | |
err = nil | |
} | |
wg.Done() | |
}() | |
c.Wait() | |
wg.Wait() | |
fmt.Printf(buffer.String()) | |
} |
This file contains 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
#!/bin/bash | |
echo "Oh hai there!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment