I'm trying to execute a command in golang, which goes to ~ path.
Like running ls ~
in terminal.
Eventually i'd like to create commands in specific directory, which is located on ~/TestDirectory, for example, git pull, mkdir, etc..
Here's what i've tried :
-
out, _ := exec.Command("ls", "~").Output()
-> Output is blank, so runningexec.Command("cd", "~")
doesn't go to ~ directory. -
out, _ := exec.Command("ls", "../..").Output()
-> Output is 2 directories above my current, but its not the way to do it since the current project might be anywhere -
Also, i've tried setting the current directory of the command, the output was nil.
cmd := exec.Command("cd") cmd.Dir = "~" cmd.Run()