123456789101112131415161718192021222324252627282930313233343536373839 |
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "os/exec"
- "time"
- )
- // BUG(maxtar) fix russian encoding in windows
- func main() {
- if len(os.Args) == 1 {
- fmt.Println("No argument was provided")
- os.Exit(1)
- }
- cmd := exec.Command(os.Args[1], os.Args[2:]...)
- cmdOut, err := cmd.StdoutPipe()
- if err != nil {
- fmt.Printf("Error get output pipe %q", err)
- os.Exit(1)
- }
- start := time.Now()
- if err = cmd.Start(); err != nil {
- fmt.Printf("Error run command: %q", err)
- os.Exit(1)
- }
- sc := bufio.NewScanner(cmdOut)
- for sc.Scan() {
- fmt.Println(sc.Text())
- }
- if err = cmd.Wait(); err != nil {
- fmt.Printf("Error wait command: %q", err)
- }
- fmt.Printf("Time elapsed: %v", time.Since(start))
- //todo add ctrl+c handler and print time in anycase
- }
|