I am trying to run an exec.Command() and was hit by the synchronization issue that has been wrapped up here
So basically I want the current HEAD sha by running the following but the output is not ready when dagger has resolved graph. Was there a solution to this already?
func getCommandOutput(bin string, args ...string) string {
cmd := exec.Command(bin, args...)
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
return string(out)
}
Also experimented with this
func getCommandOutput(bin string, args ...string) string {
var stdoutBuf, stderrBuf bytes.Buffer
cmd := exec.Command(bin, args...)
cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
return stdoutBuf.String()
}
And the caller
sha := getCommandOutput("git", "rev-parse", "--short=8", "HEAD")