Skip to content

Instantly share code, notes, and snippets.

@hyuki
Last active April 14, 2018 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/c7acc91ed42a3cbf45e40419c0ef8265 to your computer and use it in GitHub Desktop.
Save hyuki/c7acc91ed42a3cbf45e40419c0ef8265 to your computer and use it in GitHub Desktop.
手抜きのコマンド実行。1個スペース区切りの文字列を任意個与えられ、それをつないで実行する。
package main
import (
"os/exec"
"strings"
)
func execute_command(commands ...string) {
cmd := strings.Join(commands, " ")
param := strings.Split(cmd, " ")
check(cmd, exec.Command(param[0], param[1:]...).Run())
}
func check(msg string, err error) {
if err != nil {
panic(msg + "\n" + err.Error())
}
}
func main() {
execute_command("touch 1 2 3")
execute_command("touch", "4", "5 6 7 8")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment