WIP [#2]
Ursprung
8bd36090d7
Commit
00cc5a0cad
@ -0,0 +1,51 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type cmd struct {
|
||||
fullCommand string
|
||||
*exec.Cmd
|
||||
bufOut bytes.Buffer
|
||||
bufErr bytes.Buffer
|
||||
}
|
||||
|
||||
func New(name string, args string) *cmd{
|
||||
var bO, bE bytes.Buffer
|
||||
c := cmd {
|
||||
name + " " + args,
|
||||
exec.Command(name, args),
|
||||
bO,
|
||||
bE,
|
||||
}
|
||||
c.Stdout = io.MultiWriter(os.Stdout, &c.bufOut)
|
||||
c.Stderr = io.MultiWriter(os.Stderr, &c.bufErr)
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c *cmd) Execute() {
|
||||
err := c.Start()
|
||||
if err != nil {
|
||||
log.Printf("%s failed with %s\n", c.fullCommand, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cmd) GetOut() string {
|
||||
return string(c.bufOut.Bytes())
|
||||
}
|
||||
|
||||
func (c *cmd) GetErr() string {
|
||||
return string(c.bufErr.Bytes())
|
||||
}
|
||||
|
||||
func (c *cmd) WaitH() {
|
||||
err := c.Wait()
|
||||
if err != nil {
|
||||
log.Printf("%s failed with %s\n", c.fullCommand, err)
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
module proxy
|
||||
|
||||
go 1.13
|
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"proxy/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//c1 := cmd.New("sh", "-c \"vde_plug /run/vde/sw_main.sock\"")
|
||||
c2 := cmd.New("vde_plug", "/run/vde/sw_proxy.sock")
|
||||
//c1 := cmd.New("ping", "localhost", "-c 10")
|
||||
//c2 := cmd.New("nc", "google.com", "80")
|
||||
//stdin, err := c2.StdinPipe()
|
||||
//if err != nil {
|
||||
// log.Fatal(err)
|
||||
//}
|
||||
//c1.Execute()
|
||||
c2.Execute()
|
||||
//time.Sleep(time.Second)
|
||||
//io.WriteString(stdin, "GET / HTTP/1.0\n\n")
|
||||
//time.Sleep(time.Second)
|
||||
//stdin.Close()
|
||||
//c1.WaitH()
|
||||
c2.WaitH()
|
||||
|
||||
/* cmds := []*cmd.cmd{c1}
|
||||
for _, x := range cmds {
|
||||
go func(cmd *exec.Cmd) {
|
||||
fmt.Printf(x.String())
|
||||
}(cmd)
|
||||
}*/
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd := exec.Command("ping", "127.0.0.1", "-c 10")
|
||||
|
||||
var stdoutBuf, stderrBuf bytes.Buffer
|
||||
cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
|
||||
cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Fatalf("cmd.Run() failed with %s\n", err)
|
||||
}
|
||||
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
|
||||
fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr)
|
||||
}
|
In neuem Issue referenzieren