Don't environment variables get read when a process is spawned and inherited by its children? This would prevent us from performing a re-read.
package main
import ( "fmt" "os" "os/exec" "strings" "time" )
func main() { useExec := false var strout string
for { if useExec { out, err := exec.Command("/usr/bin/printenv", "FOOBAR").Output() if err != nil { panic(err) } strout = string(out) } else { strout = os.Getenv("FOOBAR") }
strout = strings.TrimSpace(strout) if strout != "hello" { fmt.Println(strout) }
time.Sleep(1000 * time.Millisecond) } }
To test: FOOBAR=hello go run main.go & export FOOBAR=foo
(now fg and kill it)
No change seen.
Don't environment variables get read when a process is spawned and inherited by its children? This would prevent us from performing a re-read.
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)
func main() {
useExec := false
var strout string
for { "/usr/bin/ printenv" , "FOOBAR").Output()
if useExec {
out, err := exec.Command(
if err != nil {
panic(err)
}
strout = string(out)
} else {
strout = os.Getenv("FOOBAR")
}
strout = strings. TrimSpace( strout) Println( strout)
if strout != "hello" {
fmt.
}
time.Sleep(1000 * time.Millisecond)
}
}
To test:
FOOBAR=hello go run main.go &
export FOOBAR=foo
(now fg and kill it)
No change seen.