try to correctly end when the process is done. still loosing output text

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-04-07 15:03:40 -07:00
parent 2929260ed6
commit 5526c9fb2b
2 changed files with 20 additions and 7 deletions

View File

@ -14,5 +14,5 @@ func main() {
// shellRAW("localhost", 5)
// simpleProcess("ping -c 10 localhost")
ping("localhost", 10)
shell("ping localhost -c 5", 10)
}

View File

@ -10,13 +10,12 @@ import "log"
// import "io"
// import "fmt"
// import "reflect"
// import "github.com/davecgh/go-spew/spew"
import "github.com/davecgh/go-spew/spew"
import "github.com/svent/go-nbreader"
func ping(hostname string, count int) {
cmdName := "ping " + hostname
cmdArgs := strings.Fields(cmdName)
func shell(cmdline string, count int) {
cmdArgs := strings.Fields(cmdline)
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
stdout, _ := cmd.StdoutPipe()
@ -48,10 +47,24 @@ func ping(hostname string, count int) {
count, err = nbrerr.Read(oneByte)
if (err != nil) {
oneByte = make([]byte, 10)
count, err = nbrerr.Read(oneByte)
f.Write([]byte(string(oneByte)))
f.Flush()
log.Println("Read() count = ", count, "err = ", err)
spew.Dump(cmd.Process)
spew.Dump(cmd.ProcessState)
cmd.Wait()
return
} else {
f.Write([]byte(string(oneByte)))
f.Flush()
}
f.Write([]byte(string(oneByte)))
f.Flush()
// spew.Dump(reflect.ValueOf(cmd.Process).Elem())
/*
*/
}
cmd.Wait()