Created
April 22, 2022 08:51
-
-
Save Feggah/792bedce8bfffe05648a9b30bb23b30e to your computer and use it in GitHub Desktop.
Send a file to the default network printer using Notepad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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