Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in golang,how can keep console window open when the program is done which startup the exe by double click

Tags:

windows

go

in windows when startup by double click the .exe and when the programe is done by os.Exit(...) so,is there anyway to keep the console window open,just like auto run an cmd command. I dontn want some solution with some PAUSE or some others thing to let it wait close.I need completed exit the program,and keep the console window .

BTW,I think some way of open another console window,but fail with this code

c :=exec.Command("start")

	if err := c.Run(); err != nil {
		fmt.Println("Error: ", err)
	}
	os.Exit(0)
like image 968
go-php-2016 Avatar asked May 06 '16 12:05

go-php-2016


1 Answers

You could call fmt.Scanf(). I know it's hack and you wouldn't want to do it in a production application, but it works.

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
    fmt.Scanf("h")
}
like image 177
CloudBranch Avatar answered Nov 15 '22 03:11

CloudBranch