main.go 753 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. "os/exec"
  7. "time"
  8. )
  9. // BUG(maxtar) fix russian encoding in windows
  10. func main() {
  11. if len(os.Args) == 1 {
  12. fmt.Println("No argument was provided")
  13. os.Exit(1)
  14. }
  15. cmd := exec.Command(os.Args[1], os.Args[2:]...)
  16. cmdOut, err := cmd.StdoutPipe()
  17. if err != nil {
  18. fmt.Printf("Error get output pipe %q", err)
  19. os.Exit(1)
  20. }
  21. start := time.Now()
  22. if err = cmd.Start(); err != nil {
  23. fmt.Printf("Error run command: %q", err)
  24. os.Exit(1)
  25. }
  26. sc := bufio.NewScanner(cmdOut)
  27. for sc.Scan() {
  28. fmt.Println(sc.Text())
  29. }
  30. if err = cmd.Wait(); err != nil {
  31. fmt.Printf("Error wait command: %q", err)
  32. }
  33. fmt.Printf("Time elapsed: %v", time.Since(start))
  34. //todo add ctrl+c handler and print time in anycase
  35. }