Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "os"
- "os/exec"
- "io"
- "strings"
- "github.com/kr/pty"
- )
- // This will be the equivalent of (echo id; cat) | /bin/sh but nicer
- // because it realocates a tty after.
- func main() {
- buffer := strings.NewReader("id\n")
- reader := io.MultiReader(buffer, os.Stdin)
- cmd := exec.Command("/bin/sh")
- tty, _ := pty.Start(cmd)
- defer tty.Close()
- go func() {
- io.Copy(tty, reader)
- }()
- go func() {
- io.Copy(os.Stdout, tty)
- }()
- cmd.Wait()
- }
Advertisement
Add Comment
Please, Sign In to add comment