Last active
April 14, 2018 01:13
-
-
Save hyuki/c7acc91ed42a3cbf45e40419c0ef8265 to your computer and use it in GitHub Desktop.
手抜きのコマンド実行。1個スペース区切りの文字列を任意個与えられ、それをつないで実行する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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