Last active
December 23, 2019 16:40
-
-
Save croese/7bbec75f29a97a4e0064be26e1f1061b to your computer and use it in GitHub Desktop.
Test go code with new processes and pipes
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 ( | |
"log" | |
"os" | |
"os/exec" | |
) | |
func main() { | |
read, write, _ := os.Pipe() | |
ls := exec.Command("ls", "-l") | |
ls.Stdout = write | |
ls.Stderr = os.Stderr | |
ls.Dir = "/Users/croese" | |
grep := exec.Command("grep", `\sP`) | |
grep.Stdin = read | |
r, w, err := os.Pipe() | |
if err != nil { | |
log.Fatalln(err) | |
} | |
grep.Stdout = w | |
grep.Stderr = os.Stderr | |
wc := exec.Command("wc", "-l") | |
wc.Stdin = r | |
wc.Stdout = os.Stdout | |
wc.Stderr = os.Stderr | |
err = ls.Start() | |
if err != nil { | |
log.Fatalln(err) | |
} | |
err = grep.Start() | |
if err != nil { | |
log.Fatalln(err) | |
} | |
err = wc.Start() | |
if err != nil { | |
log.Fatalln(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment