Skip to content

Instantly share code, notes, and snippets.

@groundwalker
Last active January 22, 2016 14:24
Show Gist options
  • Save groundwalker/1c27a65eb2751ed31049 to your computer and use it in GitHub Desktop.
Save groundwalker/1c27a65eb2751ed31049 to your computer and use it in GitHub Desktop.
Execute arbitrary commands by golang
package main
// execute arbitrary shell command
// if chmod u+s ./cmd, you can cross the bounds of shell scripts
import (
"os"
"os/exec"
"log"
)
func main() {
cmd := os.Args[1]
args := os.Args[2:]
cmdobj := exec.Command(cmd, args...)
cmdobj.Stdout = os.Stdout
cmdobj.Stderr = os.Stderr
err := cmdobj.Run()
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment