From 25cc645a4872026b5fd47e2df1a0e032c18dde6a Mon Sep 17 00:00:00 2001 From: "lion.chan" Date: Wed, 26 May 2021 22:48:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A4=BA=E4=BE=8B=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lion.chan --- .../Go/Package/OS/Exec/Golang_执行外部程序.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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)) } ```