Guest User

Untitled

a guest
Aug 17th, 2019
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4. "os"
  5. "os/exec"
  6. )
  7.  
  8. func main() {
  9. var name string
  10. var args []string
  11. var envVars []string
  12.  
  13. command := exec.Command(name, args...)
  14. command.Env = append(os.Environ(), envVars...)
  15. command.Stdout = os.Stdout
  16. command.Stderr = os.Stderr
  17. command.Stdin = os.Stdin
  18.  
  19. if err := command.Start(); err != nil {
  20. fmt.Println("Failed starting command: ", err)
  21. return err
  22. }
  23.  
  24. if err := command.Wait(); err != nil {
  25. if exiterr, ok := err.(*exec.ExitError); ok {
  26. if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
  27. fmt.Println("Exit Status: ", status.ExitStatus())
  28. return err
  29. }
  30. }
  31. fmt.Println("Failed to wait for command: ", err)
  32. return err
  33. }
  34.  
  35. return
  36. }
RAW Paste Data