Skip to content

Commit

Permalink
Do not show console on Windows
Browse files Browse the repository at this point in the history
* Update wkhtmltopdf.go

Get rid of console window appearing on Windows

* hide cmd console on windows

* hide cmd console on windows
  • Loading branch information
matwachich committed Jun 23, 2024
1 parent 0bc1e7d commit 65e9c49
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmdcfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !windows
// +build !windows

package wkhtmltopdf

import "os/exec"

func cmdConfig(cmd *exec.Cmd) {}
13 changes: 13 additions & 0 deletions cmdcfg_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build windows
// +build windows

package wkhtmltopdf

import (
"os/exec"
"syscall"
)

func cmdConfig(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 0x08000000, HideWindow: true}
}
3 changes: 3 additions & 0 deletions wkhtmltopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ func (pdfg *PDFGenerator) run(ctx context.Context) error {
// create command
cmd := exec.CommandContext(ctx, pdfg.binPath, pdfg.Args()...)

// configure the commande (different for each OS, windows only for now (hides the cmd console))
cmdConfig(cmd)

// set stderr to the provided writer, or create a new buffer
var errBuf *bytes.Buffer
cmd.Stderr = pdfg.stdErr
Expand Down

0 comments on commit 65e9c49

Please sign in to comment.