Help us shape the future of Go! Take the 2026 Go Developer Survey

guitocons

package module
v0.0.0-...-e6ef37a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2018 License: Unlicense Imports: 4 Imported by: 0

README

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)
}

Documentation

Index

Constants

View Source
const ATTACH_PARENT_PROCESS = ^uint32(0) // (DWORD)-1

Variables

This section is empty.

Functions

func Guitocons

func Guitocons() (err error)

Guitocons attach the GUI process to the parent console, so we can send "logs" & "prints" if needed

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL