func pipeCmd(cmdString, selection, defaultStatus string) string {
	cmd := exec.Command(shellName, shellOpt, cmdString)
	inPipe, err := cmd.StdinPipe()
	if err != nil {
		return err.Error()
	}
	outPipe, err := cmd.StdoutPipe()
	if err != nil {
		return err.Error()
	}
	if err := cmd.Start(); err != nil {
		return err.Error()
	}
	go func() {
		go func() {
			if _, err := io.WriteString(inPipe, selection); err != nil {
				log.Print(err)
			}
			inPipe.Close()
		}()
		var outBytes []byte
		go func() {
			if outBytes, err = ioutil.ReadAll(outPipe); err != nil {
				log.Print(err)
			}
		}()
		reportExitStatus(cmdString, cmd.Wait())
		if outBytes != nil {
			if len(outBytes) > 0 && outBytes[len(outBytes)-1] == '\n' {
				outBytes = outBytes[:len(outBytes)-1]
			}
			output := string(outBytes)
			var event sdl.UserEvent
			event.Type = userEventType
			event.Data1 = unsafe.Pointer(&pipeEvent)
			disableGC()
			event.Data2 = unsafe.Pointer(&output)
			sdl.PushEvent(&event)
		}
	}()
	return defaultStatus
}
pipeCmd pipes selection through cmdString asynchronously and returns a
status message. Results are returned on the SDL event queue.
package main
import (
	"encoding/base32"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"math/rand"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"time"
	"unsafe"
	"github.com/veandco/go-sdl2/sdl"
)
var shellName, shellOpt string  
func init() {
	rand.Seed(time.Now().UnixNano())
	if runtime.GOOS == "windows" {
		shellName, shellOpt = "cmd", "/c"
	} else {
		shellName, shellOpt = "/bin/sh", "-c"
	}
}
func flags() []string {
	args := make([]string, flag.NFlag())
	i := 0
	flag.Visit(func(f *flag.Flag) {
		args[i] = fmt.Sprintf("-%s=%v", f.Name, f.Value)
		i++
	})
	return args
}
func newInstance(filename, defaultStatus string) string {
	cmd := exec.Command(os.Args[0], append(flags(), filename)...)
	if err := cmd.Start(); err != nil {
		return err.Error()
	}
	return defaultStatus
}
func reportExitStatus(cmd string, err error) {
	var event sdl.UserEvent
	var msg string
	if err == nil {
		msg = fmt.Sprintf(`Command "%s" exited successfully.`, cmd)
	} else {
		msg = fmt.Sprintf(`Command "%s" exited with error: %v`, cmd, err)
	}
	event.Type, event.Data1 = userEventType, unsafe.Pointer(&statusEvent)
	disableGC()
	event.Data2 = unsafe.Pointer(&msg)
	sdl.PushEvent(&event)
}