diff --git a/Software/Development/Language/Go/Package/OS/Exec/Golang_执行外部程序.md b/Software/Development/Language/Go/Package/OS/Exec/Golang_执行外部程序.md index 84ae8a1..e19fb8b 100644 --- a/Software/Development/Language/Go/Package/OS/Exec/Golang_执行外部程序.md +++ b/Software/Development/Language/Go/Package/OS/Exec/Golang_执行外部程序.md @@ -7,18 +7,18 @@ ```go func MakeCmd(name string, arg ...string) *exec.Cmd { cmd := exec.Command(name, arg...) - cmd.Env = append(cmd.Env, "USER=root") - cmd.Env = append(cmd.Env, "HOME=/home/root") - cmd.Env = append(cmd.Env, "SHELL=/bin/sh") - cmd.Env = append(cmd.Env, "LOGNAME=root") - cmd.Env = append(cmd.Env, "PATH=/usr/local/bin:/usr/bin:/bin:/xt/scripts:/usr/local/sbin:/usr/sbin:/sbin:/xt/scripts") + cmd.Env = append(cmd.Env, os.Getenv("USER")) + cmd.Env = append(cmd.Env, os.Getenv("HOME")) + cmd.Env = append(cmd.Env, os.Getenv("SHELL")) + cmd.Env = append(cmd.Env, os.Getenv("LOGNAME")) + cmd.Env = append(cmd.Env, os.Getenv("PATH")) return cmd } func main() { cmd := MakeCmd("ls", "-l", "/") output, _ := cmd.Output() - fmt.Println(output) + fmt.Println(string(output)) } ```