Skip to content

Instantly share code, notes, and snippets.

@Feggah
Created April 22, 2022 08:51
Show Gist options
  • Save Feggah/792bedce8bfffe05648a9b30bb23b30e to your computer and use it in GitHub Desktop.
Save Feggah/792bedce8bfffe05648a9b30bb23b30e to your computer and use it in GitHub Desktop.
Send a file to the default network printer using Notepad
func print() error {
content := "my content"
file, err := os.CreateTemp("", "example-title")
if err != nil {
return err
}
defer func() {
file.Close()
if err := os.Remove(file.Name()); err != nil {
return err
}
}()
if _, err := file.WriteString(content); err != nil {
return err
}
cmd := exec.Command("cmd.exe", "/C", "notepad", "/p", file.Name())
if err := cmd.Run(); err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment