Created
February 20, 2018 18:54
-
-
Save icholy/5df3c8d48f5c0d50b849aeb0bc17577b 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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"log" | |
"os/exec" | |
) | |
func main() { | |
if err := run(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func run() error { | |
cmd := exec.Command("ls") | |
stdout, err := cmd.StdoutPipe() | |
if err != nil { | |
return err | |
} | |
stderr, err := cmd.StderrPipe() | |
if err != nil { | |
return err | |
} | |
if err := cmd.Start(); err != nil { | |
return err | |
} | |
scanner := bufio.NewScanner(io.MultiReader(stdout, stderr)) | |
for scanner.Scan() { | |
fmt.Println(scanner.Text()) | |
} | |
if err := scanner.Err(); err != nil { | |
return err | |
} | |
return cmd.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment