Issue
I need to source a file and get the variables from the file using golang. I am doing as can be seen below:
cmd1 := exec.Command("bash", "-c", "source fileName|echo $INFO")
out, err := cmd1.Output()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
fmt.Printf("combined out:\n%s\n", string(out))
If I execute this command in terminal on macos i see the information i need. But if I execute this command within go, I get nothing in the output. I am new to go. Any help with this is highly appreciated.
Solution
Instead of piping the command, I needed to do the below:
cmd1 := exec.Command("bash", "-c", "source fileName; echo $INFO")
Answered By - HSAR Answer Checked By - Candace Johnson (WPSolving Volunteer)