hmm. this didn't work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-04-07 13:32:52 -07:00
parent 20b61a9e9a
commit 58ab22c55f
1 changed files with 58 additions and 0 deletions

View File

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