Last active
December 18, 2023 18:17
-
-
Save lee8oi/a8a90f559fe48355f800 to your computer and use it in GitHub Desktop.
Revisions
-
lee8oi revised this gist
Mar 27, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import ( func Command(args ...string) { cmd := exec.Command(args[0], args[1:]...) cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr if err := cmd.Run(); err != nil { panic(err) } -
lee8oi revised this gist
Mar 26, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ package main import ( "os" "os/exec" ) @@ -10,7 +9,7 @@ func Command(args ...string) { cmd := exec.Command(args[0], args[1:]...) cmd.Stderr, cmd.Stdin, cmd.Stdout = os.Stdin, os.Stdout, os.Stderr if err := cmd.Run(); err != nil { panic(err) } } -
lee8oi revised this gist
Mar 26, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,9 @@ import ( func Command(args ...string) { cmd := exec.Command(args[0], args[1:]...) cmd.Stderr, cmd.Stdin, cmd.Stdout = os.Stdin, os.Stdout, os.Stderr if err := cmd.Run(); err != nil { log.Fatal(err) } } func main() { -
lee8oi revised this gist
Mar 26, 2015 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,7 @@ import ( func Command(args ...string) { cmd := exec.Command(args[0], args[1:]...) cmd.Stderr, cmd.Stdin, cmd.Stdout = os.Stdin, os.Stdout, os.Stderr if err := cmd.Start(); err != nil { log.Fatal(err) } @@ -19,5 +17,5 @@ func Command(args ...string) { func main() { Command("bash") Command("ping", "-c3", "www.google.com") } -
lee8oi revised this gist
Mar 26, 2015 . 1 changed file with 5 additions and 35 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,53 +1,23 @@ package main import ( "log" "os" "os/exec" ) func Command(args ...string) { cmd := exec.Command(args[0], args[1:]...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Start(); err != nil { log.Fatal(err) } cmd.Wait() } func main() { Command("bash") //Command("ping", "-c3", "www.google.com") } -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 9 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,6 @@ package main import ( "io" "log" "os" @@ -21,7 +19,7 @@ func Command(args ...string) { func connect(ch chan int, c *exec.Cmd) (err error) { if inp, err := c.StdinPipe(); err == nil { go loop(ch, os.Stdin, inp) if outp, err := c.StdoutPipe(); err == nil { go loop(ch, outp, os.Stdout) if errp, err := c.StderrPipe(); err == nil { @@ -35,16 +33,17 @@ func connect(ch chan int, c *exec.Cmd) (err error) { } func loop(ch chan int, inp io.Reader, outp io.Writer) { var buf = make([]byte, 1) for { _, err := inp.Read(buf) if err == nil { _, err = outp.Write(buf) if err == nil { continue } } ch <- 1 return } } -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 18 additions and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,18 +9,14 @@ import ( "os/exec" ) func Command(args ...string) { var ch = make(chan int) cmd := exec.Command(args[0], args[1:]...) connect(ch, cmd) if err := cmd.Start(); err != nil { log.Fatal(err) } _, _ = <-ch, <-ch } func connect(ch chan int, c *exec.Cmd) (err error) { @@ -38,14 +34,18 @@ func connect(ch chan int, c *exec.Cmd) (err error) { return } func loop(ch chan int, inp io.Reader, outp io.Writer) { r := bufio.NewReader(inp) for { c, err := r.ReadByte() if err != nil { if ch != nil { ch <- 1 } return } fmt.Fprintf(outp, "%c", c) } } func main() { -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,20 @@ import ( "os/exec" ) func loop(ch chan int, inp io.Reader, outp io.Writer) { r := bufio.NewReader(inp) for { c, err := r.ReadByte() if err != nil { if ch != nil { ch <- 1 } return } fmt.Fprintf(outp, "%c", c) } } func connect(ch chan int, c *exec.Cmd) (err error) { if inp, err := c.StdinPipe(); err == nil { go loop(nil, os.Stdin, inp) @@ -24,20 +38,6 @@ func connect(ch chan int, c *exec.Cmd) (err error) { return } func Command(args ...string) { var ch = make(chan int) cmd := exec.Command(args[0], args[1:]...) -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,20 +9,22 @@ import ( "os/exec" ) func connect(ch chan int, c *exec.Cmd) (err error) { if inp, err := c.StdinPipe(); err == nil { go loop(nil, os.Stdin, inp) if outp, err := c.StdoutPipe(); err == nil { go loop(ch, outp, os.Stdout) if errp, err := c.StderrPipe(); err == nil { go loop(ch, errp, os.Stderr) return nil } } } log.Fatal(err) return } func loop(ch chan int, inp io.Reader, outp io.Writer) { r := bufio.NewReader(inp) for { c, err := r.ReadByte() @@ -39,16 +41,14 @@ func start(ch chan int, inp io.Reader, outp io.Writer) { func Command(args ...string) { var ch = make(chan int) cmd := exec.Command(args[0], args[1:]...) connect(ch, cmd) if err := cmd.Start(); err != nil { log.Fatal(err) } _, _ = <-ch, <-ch } func main() { Command("bash") Command("ping", "-c3", "www.google.com") } -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 9 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import ( "os/exec" ) func pipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { var err error if inp, err = c.StdinPipe(); err == nil { if outp, err = c.StdoutPipe(); err == nil { @@ -18,11 +18,11 @@ func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { } } } log.Fatal(err) return } func start(ch chan int, inp io.Reader, outp io.Writer) { r := bufio.NewReader(inp) for { c, err := r.ReadByte() @@ -32,18 +32,17 @@ func pipe(ch chan int, inp io.Reader, outp io.Writer) { } return } fmt.Fprintf(outp, "%c", c) } } func Command(args ...string) { var ch = make(chan int) cmd := exec.Command(args[0], args[1:]...) inp, outp, errp := pipes(cmd) go start(ch, errp, os.Stderr) go start(ch, outp, os.Stdout) go start(nil, os.Stdin, inp) if err := cmd.Start(); err != nil { log.Fatal("start ", err) } -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 2 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,11 +39,7 @@ func pipe(ch chan int, inp io.Reader, outp io.Writer) { func Command(args ...string) { var cmd *exec.Cmd var ch = make(chan int) cmd = exec.Command(args[0], args[1:]...) inp, outp, errp := getPipes(cmd) go pipe(ch, errp, os.Stderr) go pipe(ch, outp, os.Stdout) @@ -56,4 +52,4 @@ func Command(args ...string) { func main() { Command("bash") } -
lee8oi revised this gist
Mar 18, 2015 . 1 changed file with 16 additions and 23 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,31 +7,29 @@ import ( "log" "os" "os/exec" ) func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { var err error if inp, err = c.StdinPipe(); err == nil { if outp, err = c.StdoutPipe(); err == nil { if errp, err = c.StderrPipe(); err == nil { return } } } log.Fatal("Failed to get pipes!") return } func pipe(ch chan int, inp io.Reader, outp io.Writer) { r := bufio.NewReader(inp) for { c, err := r.ReadByte() if err != nil { if ch != nil { ch <- 1 } return } fmt.Fprintf(outp, "%s", string(c)) @@ -40,27 +38,22 @@ func pipe(wg *sync.WaitGroup, inp io.Reader, outp io.Writer) { func Command(args ...string) { var cmd *exec.Cmd var ch = make(chan int) if len(args) > 1 { cmd = exec.Command(args[0], args[1:]...) } else { cmd = exec.Command(args[0]) } inp, outp, errp := getPipes(cmd) go pipe(ch, errp, os.Stderr) go pipe(ch, outp, os.Stdout) go pipe(nil, os.Stdin, inp) if err := cmd.Start(); err != nil { log.Fatal("start ", err) } _, _ = <-ch, <-ch } func main() { Command("bash") } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -55,9 +55,6 @@ func Command(args ...string) { if err := cmd.Start(); err != nil { log.Fatal("start ", err) } wg.Wait() } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 28 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,13 @@ package main import ( "bufio" "fmt" "io" "log" "os" "os/exec" "sync" ) func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { @@ -21,30 +24,46 @@ func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { return } func pipe(wg *sync.WaitGroup, inp io.Reader, outp io.Writer) { if wg != nil { defer wg.Done() } r := bufio.NewReader(inp) for { c, err := r.ReadByte() if err != nil { return } fmt.Fprintf(outp, "%s", string(c)) } } func Command(args ...string) { var cmd *exec.Cmd var wg sync.WaitGroup if len(args) > 1 { cmd = exec.Command(args[0], args[1:]...) } else { cmd = exec.Command(args[0]) } inp, outp, errp := getPipes(cmd) wg.Add(1) go pipe(&wg, errp, os.Stderr) wg.Add(1) go pipe(&wg, outp, os.Stdout) go pipe(nil, os.Stdin, inp) if err := cmd.Start(); err != nil { log.Fatal("start ", err) } if err := cmd.Wait(); err != nil { log.Fatal("wait ", err) } wg.Wait() } func main() { Command("bash") Command("date") Command("echo", "some text") Command("ping", "-c 3", "www.google.com") } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 46 additions and 46 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,50 +1,50 @@ package main import ( "io" "log" "os" "os/exec" ) func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { var err error if inp, err = c.StdinPipe(); err != nil { log.Fatal(err) } if outp, err = c.StdoutPipe(); err != nil { log.Fatal(err) } if errp, err = c.StderrPipe(); err != nil { log.Fatal(err) } return } func runPipe(inp io.Reader, outp io.Writer) { _, err := io.Copy(outp, inp) if err != nil { log.Println(err) } } func Command(args ...string) { var cmd *exec.Cmd if len(args) > 1 { cmd = exec.Command(args[0], args[1:]...) } else { cmd = exec.Command(args[0]) } inp, outp, errp := getPipes(cmd) go runPipe(errp, os.Stderr) go runPipe(outp, os.Stdout) go runPipe(os.Stdin, inp) if err := cmd.Run(); err != nil { log.Fatal(err) } } func main() { Command("bash") Command("ping", "-c 3", "www.google.com") } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 46 additions and 54 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,58 +1,50 @@ package main import ( "io" "log" "os" "os/exec" ) func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { var err error if inp, err = c.StdinPipe(); err != nil { log.Fatal(err) } if outp, err = c.StdoutPipe(); err != nil { log.Fatal(err) } if errp, err = c.StderrPipe(); err != nil { log.Fatal(err) } return } func runPipe(inp io.Reader, outp io.Writer) { _, err := io.Copy(outp, inp) if err != nil { log.Println(err) } } func Command(args ...string) { var cmd *exec.Cmd if len(args) > 1 { cmd = exec.Command(args[0], args[1:]...) } else { cmd = exec.Command(args[0]) } inp, outp, errp := getPipes(cmd) go runPipe(errp, os.Stderr) go runPipe(outp, os.Stdout) go runPipe(os.Stdin, inp) if err := cmd.Run(); err != nil { log.Fatal(err) } } func main() { Command("bash") Command("ping", "-c 3", "www.google.com") } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,25 +8,25 @@ import ( "sync" ) func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) { var err error if inp, err = c.StdinPipe(); err != nil { log.Fatal(err) } if outp, err = c.StdoutPipe(); err != nil { log.Fatal(err) } if errp, err = c.StderrPipe(); err != nil { log.Fatal(err) } return } func runPipe(wg *sync.WaitGroup, inp io.Reader, outp io.Writer) { if wg != nil { defer wg.Done() } _, err := io.Copy(outp, inp) if err != nil { log.Println(err) } @@ -39,16 +39,16 @@ func Command(args ...string) { } else { cmd = exec.Command(args[0]) } inp, outp, errp := getPipes(cmd) if err := cmd.Start(); err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(1) go runPipe(&wg, errp, os.Stderr) wg.Add(1) go runPipe(&wg, outp, os.Stdout) go runPipe(nil, os.Stdin, inp) wg.Wait() } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 25 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,34 @@ package main import ( "io" "log" "os" "os/exec" "sync" ) func getPipes(c *exec.Cmd) (in io.Writer, out, err io.Reader) { var e error if in, e = c.StdinPipe(); e != nil { log.Fatal(e) } if out, e = c.StdoutPipe(); e != nil { log.Fatal(e) } if err, e = c.StderrPipe(); e != nil { log.Fatal(e) } return } func runPipe(wg *sync.WaitGroup, in io.Reader, out io.Writer) { if wg != nil { defer wg.Done() } _, err := io.Copy(out, in) if err != nil { log.Println(err) } } @@ -29,18 +39,16 @@ func Command(args ...string) { } else { cmd = exec.Command(args[0]) } in, out, err := getPipes(cmd) if err := cmd.Start(); err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(1) go runPipe(&wg, err, os.Stderr) wg.Add(1) go runPipe(&wg, out, os.Stdout) go runPipe(nil, os.Stdin, in) wg.Wait() } -
lee8oi revised this gist
Jan 17, 2015 . 1 changed file with 1 addition and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,29 +29,22 @@ func Command(args ...string) { } else { cmd = exec.Command(args[0]) } stdout, _ := cmd.StdoutPipe() stderr, _ := cmd.StderrPipe() stdin, _ := cmd.StdinPipe() if err := cmd.Start(); err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(1) go runPipe(&wg, stderr, os.Stderr) wg.Add(1) go runPipe(&wg, stdout, os.Stdout) go runPipe(nil, os.Stdin, stdin) wg.Wait() } func main() { Command("bash") Command("ping", "-c 3", "www.google.com") } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 13 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,8 +22,13 @@ func runPipe(wg *sync.WaitGroup, in interface{}, out interface{}) { } } func Command(args ...string) { var cmd *exec.Cmd if len(args) > 1 { cmd = exec.Command(args[0], args[1:]...) } else { cmd = exec.Command(args[0]) } stdout, _ := cmd.StdoutPipe() stderr, _ := cmd.StderrPipe() @@ -32,7 +37,7 @@ func main() { if err := cmd.Start(); err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(1) @@ -45,3 +50,8 @@ func main() { wg.Wait() } func main() { Command("bash") Command("ping", "-c 3", "www.google.com") } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,8 +23,6 @@ func runPipe(wg *sync.WaitGroup, in interface{}, out interface{}) { } func main() { cmd := exec.Command("bash") stdout, _ := cmd.StdoutPipe() @@ -34,7 +32,9 @@ func main() { if err := cmd.Start(); err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(1) go runPipe(&wg, stderr, os.Stderr) -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 9 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,14 +3,14 @@ package main import ( "bufio" "fmt" "io" "log" "os" "os/exec" "sync" ) func runPipe(wg *sync.WaitGroup, in interface{}, out interface{}) { defer wg.Done() r := bufio.NewReader(in.(io.Reader)) for { @@ -24,21 +24,24 @@ func runPipe (wg *sync.WaitGroup, in interface{}, out interface{}) { func main() { var wg sync.WaitGroup cmd := exec.Command("bash") stdout, _ := cmd.StdoutPipe() stderr, _ := cmd.StderrPipe() stdin, _ := cmd.StdinPipe() if err := cmd.Start(); err != nil { log.Fatal(err) } wg.Add(1) go runPipe(&wg, stderr, os.Stderr) wg.Add(1) go runPipe(&wg, stdout, os.Stdout) go runPipe(nil, os.Stdin, stdin) wg.Wait() } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 21 additions and 41 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,61 +4,41 @@ import ( "bufio" "fmt" "log" "io" "os" "os/exec" "sync" ) func runPipe (wg *sync.WaitGroup, in interface{}, out interface{}) { defer wg.Done() r := bufio.NewReader(in.(io.Reader)) for { c, err := r.ReadByte() if err != nil { return } fmt.Fprintf(out.(io.Writer), "%s", string(c)) } } func main() { var wg sync.WaitGroup cmd := exec.Command("bash") stdout, _ := cmd.StdoutPipe() stderr, _ := cmd.StderrPipe() stdin, _ := cmd.StdinPipe() if err := cmd.Start(); err != nil { log.Fatal(err) } wg.Add(1) go runPipe(&wg, stderr, os.Stderr) wg.Add(1) go runPipe(&wg, stdout, os.Stdout) go runPipe(nil, os.Stdin, stdin) wg.Wait() } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 4 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,26 +12,17 @@ import ( func main() { cmd := exec.Command("bash") stdout, _ := cmd.StdoutPipe() sread := bufio.NewReader(stdout) stderr, _ := cmd.StderrPipe() eread := bufio.NewReader(stderr) stdin, _ := cmd.StdinPipe() iread := bufio.NewReader(os.Stdin) if err := cmd.Start(); err != nil { log.Fatal(err) } var wg sync.WaitGroup -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 11 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ package main import ( "bufio" "fmt" @@ -8,7 +8,7 @@ import ( "os/exec" "sync" ) func main() { cmd := exec.Command("bash") @@ -17,25 +17,25 @@ func main() { log.Fatal("StdoutPipe", err) } sread := bufio.NewReader(stdout) stderr, err := cmd.StderrPipe() if err != nil { log.Fatal("StderrPipe", err) } eread := bufio.NewReader(stderr) stdin, err := cmd.StdinPipe() if err != nil { log.Fatal("StdinPipe", err) } iread := bufio.NewReader(os.Stdin) if err := cmd.Start(); err != nil { log.Fatal("CmdStart", err) } var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() @@ -47,7 +47,7 @@ func main() { fmt.Fprintf(os.Stderr, "%s", string(c)) } }() wg.Add(1) go func() { defer wg.Done() @@ -59,16 +59,15 @@ func main() { fmt.Fprintf(os.Stdout, "%s", string(c)) } }() go func() { for { c, err := iread.ReadByte() if err != nil { return } fmt.Fprintf(stdin, "%s", string(c)) } }() wg.Wait() } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 22 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,14 @@ package main import ( "bufio" "fmt" "log" "os" "os/exec" "sync" ) func main() { cmd := exec.Command("bash") @@ -33,31 +34,41 @@ func main() { log.Fatal("CmdStart", err) } var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() for { c, err := eread.ReadByte() if err != nil { return } fmt.Fprintf(os.Stderr, "%s", string(c)) } }() wg.Add(1) go func() { defer wg.Done() for { c, err := sread.ReadByte() if err != nil { return } fmt.Fprintf(os.Stdout, "%s", string(c)) } }() go func () { for { c, err := iread.ReadByte() if err != nil { log.Fatal("iread ", err) } fmt.Fprintf(stdin, "%s", string(c)) } }() wg.Wait() } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func main() { for { c, err := eread.ReadByte() if err != nil { log.Fatal("eread ", err) } fmt.Fprintf(os.Stderr, "%s", string(c)) } @@ -47,17 +47,17 @@ func main() { for { c, err := sread.ReadByte() if err != nil { log.Fatal("sread ", err) } fmt.Fprintf(os.Stdout, "%s", string(c)) } }() for { c, err := iread.ReadByte() if err != nil { log.Fatal("iread ", err) } fmt.Fprintf(stdin, "%s", string(c)) } } -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ func main() { if err != nil { return } fmt.Fprintf(os.Stderr, "%s", string(c)) } }() @@ -49,7 +49,7 @@ func main() { if err != nil { return } fmt.Fprintf(os.Stdout, "%s", string(c)) } }() -
lee8oi revised this gist
Jan 16, 2015 . 1 changed file with 6 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -53,13 +53,11 @@ func main() { } }() for { c, err := iread.ReadString('\n') if err != nil { return } fmt.Fprintf(stdin, "%s", c) } } -
lee8oi renamed this gist
Jan 16, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.
NewerOlder