mosers
/
eaas-vde-proxy
Archiviert
1
0
Fork 0
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

50 Zeilen
938 B
Go

package cmd
import (
"io"
"log"
"os"
"os/exec"
)
// Cmd Overloads the exec.Cmd class to save the full command
// and adds custom input/output pipes
type Cmd struct {
fullCommand string
*exec.Cmd
inReader io.Reader
InWriter io.Writer
OutReader io.Reader
outWriter io.Writer
}
// Start creates a new cmd object with given arguments, runs and then returns it
func Start(args string) (*Cmd, io.Reader, io.Writer) {
ir, iw := io.Pipe()
or, ow := io.Pipe()
c := Cmd{
"vde_plug " + args,
exec.Command("vde_plug", args),
ir,
iw,
or,
ow,
}
c.Stdout = c.outWriter
c.Stdin = c.inReader
c.Stderr = os.Stderr
err := c.Start()
if err != nil {
log.Printf("%s failed with %s\n", c.fullCommand, err)
}
return &c, c.OutReader, c.InWriter
}
// WaitH runs Cmd.Wait() and catches the possible error
func (c *Cmd) WaitH() {
err := c.Wait()
if err != nil {
log.Printf("%s failed with %s\n", c.fullCommand, err)
}
}