Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Last active April 13, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextanhongpin/a90e68fe7842c5036319f90083bac7b2 to your computer and use it in GitHub Desktop.
Save alextanhongpin/a90e68fe7842c5036319f90083bac7b2 to your computer and use it in GitHub Desktop.
Sample golang code that pipes the dynamic .dot file data to external graphviz process to write the .png file
// -- IMPORTSS NOT SHOWN
path, _ := exec.LookPath("dot")
cmd := exec.Command(path, fmt.Sprintf("-T%s", "png"))
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
go func() {
defer stdin.Close()
// Writes the data to stdin.
Render(data, stdin)
}()
writeCmd, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
mode := int(0644)
ioutil.WriteFile("out.png", writeCmd, os.FileMode(mode))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment