From 58ab22c55fd78d920513fe66dd53e41dcf3e0674 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 7 Apr 2019 13:32:52 -0700 Subject: [PATCH] hmm. this didn't work Signed-off-by: Jeff Carr --- random-output/shell.go | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/random-output/shell.go b/random-output/shell.go index 0be9291..ce177ec 100644 --- a/random-output/shell.go +++ b/random-output/shell.go @@ -238,3 +238,61 @@ func stdoutExec(prompt string, timeout int) { cmd.Wait() } + +func brokenping(hostname string, count int) { + cmdName := "ping " + hostname + cmdArgs := strings.Fields(cmdName) + + cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + + stdout, _ := cmd.StdoutPipe() +/* + stderr, _ := cmd.StderrPipe() + merged := io.MultiReader(stderr, stdout) + scanner := bufio.NewScanner(merged) +*/ + + scanner := bufio.NewScanner(stdout) + + cmd.Start() + + f := bufio.NewWriter(os.Stdout) + + for { + time.Sleep(100 * time.Millisecond) // only check the buffer 10 times a second + log.Println("sleep done") + + smallbuf := make([]byte, 1024) // make a 1K buffer. just do this each time so it's empty + // stuff, err := stdout.Read(smallbuf) + smallbuf = scanner.Bytes() + if len(smallbuf) != 0 { + log.Println("stuff:", smallbuf) + // f.Write([]byte("test \n")) + f.Write(smallbuf) + f.Flush() + } +/* + if err != nil { + log.Println("ERROR:", err.Error()) + } +*/ + +/* + smallbuf = make([]byte, 1024) // make a 1K buffer. just do this each time so it's empty + log.Println("try stderr") + stuff, err = stderr.Read(smallbuf) + log.Println("tried stderr") + if stuff != 0 { + log.Println("stuff:", stuff) + f.Write([]byte("test \n")) + f.Write(smallbuf) + f.Flush() + } + if err != nil { + log.Println("ERROR:", err.Error()) + } +*/ + } + + cmd.Wait() +}