working ping output

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-04-07 13:02:17 -07:00
parent 1b8a789787
commit 20b61a9e9a
1 changed files with 11 additions and 18 deletions

View File

@ -43,31 +43,24 @@ func ping(hostname string, count int) {
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
stdout, _ := cmd.StdoutPipe()
cmd.Start()
oneByte := make([]byte, 100)
f := bufio.NewWriter(os.Stdout)
f.Write(oneByte)
f.Flush()
num := 1
for {
/*
const delay = 1000 * time.Millisecond
time.Sleep(delay / 2)
// log.Println("sleep done")
oneByte := make([]byte, 100)
stuff, err := stdout.Read(oneByte)
if stuff != 0 {
// log.Println("stuff:", stuff)
// f.Write([]byte("test \n"))
f.Write(oneByte)
f.Flush()
}
if err != nil {
log.Println("ERROR:", err.Error())
break
} else {
log.Println("stuff =", stuff)
break
}
*/
r := bufio.NewReader(stdout)
line, _, _ := r.ReadLine()
fmt.Println(string(line))
num = num + 1
if num > count {
os.Exit(0)
}
}