본문 바로가기
Programming/Golang

Golang GUI(Webview) - 다른 프로그램(exe파일) 실행하기

by Wilkyway 2021. 11. 30.
반응형

 

Go언어로 다른 프로그램을 실행시키는 방법을 알아보겠습니다. 이번에도 역시 webview로 GUI를 구성하고, 버튼이 클릭되면 whale 브라우저를 실행하도록 해보겠습니다.

기존에 Webview가 설치되어있다면 다른 라이브러리 설치는 필요 없습니다. 단 os.exec 라이브러리를 사용하므로 임포트..정도는 필요합니다.

 

<main.go>

package main

import (
	"os/exec"

	"github.com/webview/webview"
)

func main() {
	w := webview.New(true)
	defer w.Destroy()
	w.SetSize(600, 200, webview.HintNone)
	// Create a GoLang function callable from JS
	w.Bind("hello", func() string { return "World!" })
	w.Bind("gorun", gorun)

	// Create UI with data URI
	w.Navigate(`data:text/html,
	 <!doctype html>
	 <html>
		<head><title>Hello</title></head>
		<body><h1>Run Servers!</h1></body>
		<button onclick="gorun();">RUN</button>
		<script> hello().then((x) => { console.log(x) }) </script>
	 </html>`)

	w.Run()
}

func gorun() {
	cmd := exec.Command("C:\\Program Files\\Naver\\Naver Whale\\Application\\whale.exe", "www.google.com")
	cmd.Start()
}

 

빨리 Gin 프로그램을 붙여 돌려봐야겠네요..^^

반응형

댓글