카테고리 없음

Go언어 Windows 10 cmd창 숨기기

KayEsQuo 2021. 7. 19. 16:53

애플리케이션을 빌드하고 exe파일을 실행할때 검은색 화면과 함께 새 windows창이 뜨는것을 볼 수 있다. 이러한 CMD 창을 숨기기 위한 코드는 아래와 같다.

 

package main

import (
	"fmt"

	"github.com/gonutz/w32"
)

func main() {

	hideConsole()
	command()    // command 명령함수 호출 (생략)
}

func hideConsole() {
	console := w32.GetConsoleWindow()
	if console == 0 {
		return // no console attached
	}

	_, consoleProcID := w32.GetWindowThreadProcessId(console)
	if w32.GetCurrentProcessId() == consoleProcID {
		w32.ShowWindowAsync(console, w32.SW_HIDE)
	}
}

 

참고

https://stackoverflow.com/questions/42500570/how-to-hide-command-prompt-window-when-using-exec-in-golang/46233782

 

How to hide command prompt window when using Exec in Golang?

say i have the following code, using syscall to hide command line window process := exec.Command(name, args...) process.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} err := process.Star...

stackoverflow.com