优化示例程序.

Signed-off-by: lion.chan <cy187lion@sina.com>
This commit is contained in:
lion.chan 2021-05-26 22:48:00 +08:00
parent 35d3e33070
commit 25cc645a48
1 changed files with 6 additions and 6 deletions

View File

@ -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))
}
```