Advertisement
Guest User

Untitled

a guest
May 7th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "os/exec"
  6. "strings"
  7. )
  8.  
  9. func Cmd(cmd string) {
  10. fmt.Println("command is ", cmd)
  11. parts := strings.Fields(cmd)
  12. head := parts[0]
  13. parts = parts[1:len(parts)]
  14. out, err := exec.Command(head, parts...).Output()
  15. if err != nil {
  16. fmt.Printf("%s", err)
  17. }
  18. fmt.Println("out")
  19. fmt.Println(string(out))
  20. }
  21.  
  22. func main() {
  23. Cmd(`echo "hello world" | /usr/bin/pbcopy`)
  24. }
  25.  
  26. command is echo "hello world" | /usr/bin/pbcopy
  27. out
  28. "hello world" | /usr/bin/pbcopy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement