Skip to content

package to attach a Windows "GUI" program to his calling process console

License

Notifications You must be signed in to change notification settings

ffred/guitocons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

guitocons :

attach the GUI stdout & stderr outputs to the calling process console (if there is one)

install with : go get github.com/ffred/guitocons

On Windows if you build your Go project with '-ldflags="-H windowsgui' parameters, you got a "GUI" program, with no console. even if you launch your program from a console, you won't have any output on it from 'fmt' or 'log' functions. I tried a few GUI samples on Go witch was outputting values on the console and wasn't showing any of it for me on Windows, so I search a way to change that.

this small package attach the parent process console to your GUI program, so you can still output logs during development or whatever you could need for your final program.

I'm rather new to Go programming, so there's probably better or different ways to do that, but for now its working... :-)

there's not much informations with Go language about that GUI/console "problem" online. I found what I needed here.

a simple way to test it is by building this small code with '-ldflags="-H windowsgui' parameters and launch it from a console, or not :

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/ffred/guitocons"
)

func main() {
	err1 := guitocons.Guitocons()
	if err1 == nil {
		log.Println("err console OK..")
		fmt.Println("std console OK..")
		os.Stderr.WriteString("Msg to STDERR\n")

		var s string
		fmt.Scanln(&s)
		os.Exit(0)
	}
	log.Println(err1)
}

About

package to attach a Windows "GUI" program to his calling process console

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages