Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os/exec"
- "strings"
- )
- func Cmd(cmd string) {
- fmt.Println("command is ", cmd)
- parts := strings.Fields(cmd)
- head := parts[0]
- parts = parts[1:len(parts)]
- out, err := exec.Command(head, parts...).Output()
- if err != nil {
- fmt.Printf("%s", err)
- }
- fmt.Println("out")
- fmt.Println(string(out))
- }
- func main() {
- Cmd(`echo "hello world" | /usr/bin/pbcopy`)
- }
- command is echo "hello world" | /usr/bin/pbcopy
- out
- "hello world" | /usr/bin/pbcopy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement