Skip to content

Instantly share code, notes, and snippets.

@lee8oi
Last active December 18, 2023 18:17
Show Gist options
  • Save lee8oi/a8a90f559fe48355f800 to your computer and use it in GitHub Desktop.
Save lee8oi/a8a90f559fe48355f800 to your computer and use it in GitHub Desktop.

Revisions

  1. lee8oi revised this gist Mar 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion goshell.go
    Original 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.Stderr, cmd.Stdin, cmd.Stdout = os.Stdin, os.Stdout, os.Stderr
    cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
    if err := cmd.Run(); err != nil {
    panic(err)
    }
  2. lee8oi revised this gist Mar 26, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    package main

    import (
    "log"
    "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 {
    log.Fatal(err)
    panic(err)
    }
    }

  3. lee8oi revised this gist Mar 26, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions goshell.go
    Original 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.Start(); err != nil {
    if err := cmd.Run(); err != nil {
    log.Fatal(err)
    }
    cmd.Wait()
    }

    func main() {
  4. lee8oi revised this gist Mar 26, 2015. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions goshell.go
    Original 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.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    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")
    Command("ping", "-c3", "www.google.com")
    }
  5. lee8oi revised this gist Mar 26, 2015. 1 changed file with 5 additions and 35 deletions.
    40 changes: 5 additions & 35 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -1,53 +1,23 @@
    package main

    import (
    "io"
    "log"
    "os"
    "os/exec"
    )

    func Command(args ...string) {
    var ch = make(chan int)
    cmd := exec.Command(args[0], args[1:]...)
    connect(ch, cmd)
    cmd.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    if err := cmd.Start(); err != nil {
    log.Fatal(err)
    }
    _, _ = <-ch, <-ch
    }

    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 {
    go loop(ch, errp, os.Stderr)
    return nil
    }
    }
    }
    log.Fatal(err)
    return
    }

    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
    }
    cmd.Wait()
    }

    func main() {
    Command("bash")
    Command("ping", "-c3", "www.google.com")
    //Command("ping", "-c3", "www.google.com")
    }
  6. lee8oi revised this gist Mar 18, 2015. 1 changed file with 9 additions and 10 deletions.
    19 changes: 9 additions & 10 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    package main

    import (
    "bufio"
    "fmt"
    "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(nil, os.Stdin, inp)
    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) {
    r := bufio.NewReader(inp)
    var buf = make([]byte, 1)
    for {
    c, err := r.ReadByte()
    if err != nil {
    if ch != nil {
    ch <- 1
    _, err := inp.Read(buf)
    if err == nil {
    _, err = outp.Write(buf)
    if err == nil {
    continue
    }
    return
    }
    fmt.Fprintf(outp, "%c", c)
    ch <- 1
    return
    }
    }

  7. lee8oi revised this gist Mar 18, 2015. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -9,18 +9,14 @@ 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 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 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)
    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)
    }
    _, _ = <-ch, <-ch
    }

    func main() {
  8. lee8oi revised this gist Mar 18, 2015. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions goshell.go
    Original 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 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 Command(args ...string) {
    var ch = make(chan int)
    cmd := exec.Command(args[0], args[1:]...)
  9. lee8oi revised this gist Mar 18, 2015. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -9,20 +9,22 @@ 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 {
    if errp, err = c.StderrPipe(); err == nil {
    return
    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 start(ch chan int, inp io.Reader, outp io.Writer) {
    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:]...)
    inp, outp, errp := pipes(cmd)
    go start(ch, errp, os.Stderr)
    go start(ch, outp, os.Stdout)
    go start(nil, os.Stdin, inp)
    connect(ch, cmd)
    if err := cmd.Start(); err != nil {
    log.Fatal("start ", err)
    log.Fatal(err)
    }
    _, _ = <-ch, <-ch
    }

    func main() {
    Command("bash")
    Command("ping", "-c3", "www.google.com")
    }
  10. lee8oi revised this gist Mar 18, 2015. 1 changed file with 9 additions and 10 deletions.
    19 changes: 9 additions & 10 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ import (
    "os/exec"
    )

    func getPipes(c *exec.Cmd) (inp io.Writer, outp, errp io.Reader) {
    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("Failed to get pipes!")
    log.Fatal(err)
    return
    }

    func pipe(ch chan int, inp io.Reader, outp io.Writer) {
    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, "%s", string(c))
    fmt.Fprintf(outp, "%c", c)
    }
    }

    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)
    go pipe(nil, os.Stdin, inp)
    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)
    }
  11. lee8oi revised this gist Mar 18, 2015. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions goshell.go
    Original 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)
    if len(args) > 1 {
    cmd = exec.Command(args[0], args[1:]...)
    } else {
    cmd = exec.Command(args[0])
    }
    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")
    }
    }
  12. lee8oi revised this gist Mar 18, 2015. 1 changed file with 16 additions and 23 deletions.
    39 changes: 16 additions & 23 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -7,31 +7,29 @@ import (
    "log"
    "os"
    "os/exec"
    "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)
    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(wg *sync.WaitGroup, inp io.Reader, outp io.Writer) {
    if wg != nil {
    defer wg.Done()
    }
    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 wg sync.WaitGroup
    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)
    wg.Add(1)
    go pipe(&wg, errp, os.Stderr)
    wg.Add(1)
    go pipe(&wg, outp, os.Stdout)
    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)
    }
    wg.Wait()
    _, _ = <-ch, <-ch
    }

    func main() {
    Command("bash")
    Command("date")
    Command("echo", "some text")
    Command("ping", "-c 3", "www.google.com")
    }
    }
  13. lee8oi revised this gist Jan 17, 2015. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions goshell.go
    Original 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)
    }
    if err := cmd.Wait(); err != nil {
    log.Fatal("wait ", err)
    }
    wg.Wait()
    }

  14. lee8oi revised this gist Jan 17, 2015. 1 changed file with 28 additions and 9 deletions.
    37 changes: 28 additions & 9 deletions goshell.go
    Original 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 runPipe(inp io.Reader, outp io.Writer) {
    _, err := io.Copy(outp, inp)
    if err != nil {
    log.Println(err)
    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)
    go runPipe(errp, os.Stderr)
    go runPipe(outp, os.Stdout)
    go runPipe(os.Stdin, inp)
    if err := cmd.Run(); err != nil {
    log.Fatal(err)
    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")
    }
  15. lee8oi revised this gist Jan 17, 2015. 1 changed file with 46 additions and 46 deletions.
    92 changes: 46 additions & 46 deletions goshell.go
    Original 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
    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)
    }

    func runPipe(inp io.Reader, outp io.Writer) {
    _, err := io.Copy(outp, inp)
    if err != nil {
    log.Println(err)
    }
    if outp, err = c.StdoutPipe(); err != nil {
    log.Fatal(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)
    }
    if errp, err = c.StderrPipe(); err != nil {
    log.Fatal(err)
    }

    func main() {
    Command("bash")
    Command("ping", "-c 3", "www.google.com")
    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")
    }
  16. lee8oi revised this gist Jan 17, 2015. 1 changed file with 46 additions and 54 deletions.
    100 changes: 46 additions & 54 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -1,58 +1,50 @@
    package main

    import (
    "io"
    "log"
    "os"
    "os/exec"
    "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)
    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
    }
    if outp, err = c.StdoutPipe(); err != nil {
    log.Fatal(err)

    func runPipe(inp io.Reader, outp io.Writer) {
    _, err := io.Copy(outp, inp)
    if err != nil {
    log.Println(err)
    }
    }
    if errp, err = c.StderrPipe(); err != nil {
    log.Fatal(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)
    }
    }
    return
    }

    func runPipe(wg *sync.WaitGroup, inp io.Reader, outp io.Writer) {
    if wg != nil {
    defer wg.Done()

    func main() {
    Command("bash")
    Command("ping", "-c 3", "www.google.com")
    }
    _, 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)
    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()
    }

    func main() {
    Command("bash")
    Command("ping", "-c 3", "www.google.com")
    }
  17. lee8oi revised this gist Jan 17, 2015. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -8,25 +8,25 @@ import (
    "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)
    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 out, e = c.StdoutPipe(); e != nil {
    log.Fatal(e)
    if outp, err = c.StdoutPipe(); err != nil {
    log.Fatal(err)
    }
    if err, e = c.StderrPipe(); e != nil {
    log.Fatal(e)
    if errp, err = c.StderrPipe(); err != nil {
    log.Fatal(err)
    }
    return
    }

    func runPipe(wg *sync.WaitGroup, in io.Reader, out io.Writer) {
    func runPipe(wg *sync.WaitGroup, inp io.Reader, outp io.Writer) {
    if wg != nil {
    defer wg.Done()
    }
    _, err := io.Copy(out, in)
    _, 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])
    }
    in, out, err := getPipes(cmd)
    inp, outp, errp := getPipes(cmd)
    if err := cmd.Start(); err != nil {
    log.Fatal(err)
    }
    var wg sync.WaitGroup
    wg.Add(1)
    go runPipe(&wg, err, os.Stderr)
    go runPipe(&wg, errp, os.Stderr)
    wg.Add(1)
    go runPipe(&wg, out, os.Stdout)
    go runPipe(nil, os.Stdin, in)
    go runPipe(&wg, outp, os.Stdout)
    go runPipe(nil, os.Stdin, inp)
    wg.Wait()
    }

  18. lee8oi revised this gist Jan 17, 2015. 1 changed file with 25 additions and 17 deletions.
    42 changes: 25 additions & 17 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,34 @@
    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 {
    c, err := r.ReadByte()
    if err != nil {
    return
    }
    fmt.Fprintf(out.(io.Writer), "%s", string(c))
    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])
    }
    stdout, _ := cmd.StdoutPipe()
    stderr, _ := cmd.StderrPipe()
    stdin, _ := cmd.StdinPipe()
    in, out, err := getPipes(cmd)
    if err := cmd.Start(); err != nil {
    log.Fatal(err)
    }
    var wg sync.WaitGroup
    wg.Add(1)
    go runPipe(&wg, stderr, os.Stderr)
    go runPipe(&wg, err, os.Stderr)
    wg.Add(1)
    go runPipe(&wg, stdout, os.Stdout)
    go runPipe(nil, os.Stdin, stdin)
    go runPipe(&wg, out, os.Stdout)
    go runPipe(nil, os.Stdin, in)
    wg.Wait()
    }

  19. lee8oi revised this gist Jan 17, 2015. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions goshell.go
    Original 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("bash")
    Command("ping", "-c 3", "www.google.com")
    }
  20. lee8oi revised this gist Jan 16, 2015. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,13 @@ func runPipe(wg *sync.WaitGroup, in interface{}, out interface{}) {
    }
    }

    func main() {
    cmd := exec.Command("bash")
    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")
    }
  21. lee8oi revised this gist Jan 16, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -23,8 +23,6 @@ func runPipe(wg *sync.WaitGroup, in interface{}, out interface{}) {
    }

    func main() {
    var wg sync.WaitGroup

    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)

  22. lee8oi revised this gist Jan 16, 2015. 1 changed file with 9 additions and 6 deletions.
    15 changes: 9 additions & 6 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,14 @@ package main
    import (
    "bufio"
    "fmt"
    "log"
    "io"
    "log"
    "os"
    "os/exec"
    "sync"
    )

    func runPipe (wg *sync.WaitGroup, in interface{}, out interface{}) {
    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()
    }
  23. lee8oi revised this gist Jan 16, 2015. 1 changed file with 21 additions and 41 deletions.
    62 changes: 21 additions & 41 deletions goshell.go
    Original 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()
    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

    wg.Add(1)
    go func() {
    defer wg.Done()
    for {
    c, err := eread.ReadByte()
    if err != nil {
    return
    }
    fmt.Fprintf(os.Stderr, "%s", string(c))
    }
    }()

    go runPipe(&wg, stderr, os.Stderr)

    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 {
    return
    }
    fmt.Fprintf(stdin, "%s", string(c))
    }
    }()
    go runPipe(&wg, stdout, os.Stdout)

    go runPipe(nil, os.Stdin, stdin)

    wg.Wait()
    }
  24. lee8oi revised this gist Jan 16, 2015. 1 changed file with 4 additions and 13 deletions.
    17 changes: 4 additions & 13 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -12,26 +12,17 @@ import (
    func main() {
    cmd := exec.Command("bash")

    stdout, err := cmd.StdoutPipe()
    if err != nil {
    log.Fatal("StdoutPipe", err)
    }
    stdout, _ := cmd.StdoutPipe()
    sread := bufio.NewReader(stdout)

    stderr, err := cmd.StderrPipe()
    if err != nil {
    log.Fatal("StderrPipe", err)
    }
    stderr, _ := cmd.StderrPipe()
    eread := bufio.NewReader(stderr)

    stdin, err := cmd.StdinPipe()
    if err != nil {
    log.Fatal("StdinPipe", err)
    }
    stdin, _ := cmd.StdinPipe()
    iread := bufio.NewReader(os.Stdin)

    if err := cmd.Start(); err != nil {
    log.Fatal("CmdStart", err)
    log.Fatal(err)
    }

    var wg sync.WaitGroup
  25. lee8oi revised this gist Jan 16, 2015. 1 changed file with 11 additions and 12 deletions.
    23 changes: 11 additions & 12 deletions goshell.go
    Original 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 () {

    go func() {
    for {
    c, err := iread.ReadByte()
    if err != nil {
    log.Fatal("iread ", err)
    return
    }
    fmt.Fprintf(stdin, "%s", string(c))
    }
    }()

    wg.Wait()
    }
    }
  26. lee8oi revised this gist Jan 16, 2015. 1 changed file with 22 additions and 11 deletions.
    33 changes: 22 additions & 11 deletions goshell.go
    Original 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 {
    log.Fatal("eread ", err)
    return
    }
    fmt.Fprintf(os.Stderr, "%s", string(c))
    }
    }()

    wg.Add(1)
    go func() {
    defer wg.Done()
    for {
    c, err := sread.ReadByte()
    if err != nil {
    log.Fatal("sread ", err)
    return
    }
    fmt.Fprintf(os.Stdout, "%s", string(c))
    }
    }()

    for {
    c, err := iread.ReadByte()
    if err != nil {
    log.Fatal("iread ", err)
    go func () {
    for {
    c, err := iread.ReadByte()
    if err != nil {
    log.Fatal("iread ", err)
    }
    fmt.Fprintf(stdin, "%s", string(c))
    }
    fmt.Fprintf(stdin, "%s", string(c))
    }
    }
    }()

    wg.Wait()
    }
  27. lee8oi revised this gist Jan 16, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ func main() {
    for {
    c, err := eread.ReadByte()
    if err != nil {
    return
    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 {
    return
    log.Fatal("sread ", err)
    }
    fmt.Fprintf(os.Stdout, "%s", string(c))
    }
    }()

    for {
    c, err := iread.ReadString('\n')
    c, err := iread.ReadByte()
    if err != nil {
    return
    log.Fatal("iread ", err)
    }
    fmt.Fprintf(stdin, "%s", c)
    fmt.Fprintf(stdin, "%s", string(c))
    }
    }
  28. lee8oi revised this gist Jan 16, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@ func main() {
    if err != nil {
    return
    }
    fmt.Printf("%s", string(c))
    fmt.Fprintf(os.Stderr, "%s", string(c))
    }
    }()

    @@ -49,7 +49,7 @@ func main() {
    if err != nil {
    return
    }
    fmt.Printf("%s", string(c))
    fmt.Fprintf(os.Stdout, "%s", string(c))
    }
    }()

  29. lee8oi revised this gist Jan 16, 2015. 1 changed file with 6 additions and 8 deletions.
    14 changes: 6 additions & 8 deletions goshell.go
    Original file line number Diff line number Diff line change
    @@ -53,13 +53,11 @@ func main() {
    }
    }()

    func() {
    for {
    c, err := iread.ReadString('\n')
    if err != nil {
    return
    }
    fmt.Fprintf(stdin, "%s", c)
    for {
    c, err := iread.ReadString('\n')
    if err != nil {
    return
    }
    }()
    fmt.Fprintf(stdin, "%s", c)
    }
    }
  30. lee8oi renamed this gist Jan 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.