我一直在尝试运行一个命令,以便不必使用 bash 脚本,而是使用 go 来运行命令。HOME=/home/gogopowerrangers 在 ubuntu 18.04 上
const systemInfoLoc string = "$HOME/systemvar.txt"
//I've tried to run with full path as well here
getSystemKernel := exec.Command("uname", "-s", ">>", "home/username/system.txt")
getSystemKernel.Run()
//^doesn't seem to return anything
//or
getsystemvar,_ = exec.Command("echo", "$USER", ">", "$HOME/systemvar.txt").Output
fmt.Println(string(getsystemvar))
//here even after the system doesn't seen to recognize $USER or $HOME or actually get the variables
我的语法错误吗?我可以将参数作为 args []string 传递,但这似乎没有什么区别。我知道如果我将它们写入 CMD 行或 bash 脚本中它们会起作用。如果您发现有问题,请告诉我。
慕容3067478
郎朗坤
相关分类