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:
parent
2929260ed6
commit
5526c9fb2b
|
@ -14,5 +14,5 @@ func main() {
|
||||||
|
|
||||||
// shellRAW("localhost", 5)
|
// shellRAW("localhost", 5)
|
||||||
// simpleProcess("ping -c 10 localhost")
|
// simpleProcess("ping -c 10 localhost")
|
||||||
ping("localhost", 10)
|
shell("ping localhost -c 5", 10)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,12 @@ import "log"
|
||||||
// import "io"
|
// import "io"
|
||||||
// import "fmt"
|
// import "fmt"
|
||||||
// import "reflect"
|
// import "reflect"
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
import "github.com/svent/go-nbreader"
|
import "github.com/svent/go-nbreader"
|
||||||
|
|
||||||
func ping(hostname string, count int) {
|
func shell(cmdline string, count int) {
|
||||||
cmdName := "ping " + hostname
|
cmdArgs := strings.Fields(cmdline)
|
||||||
cmdArgs := strings.Fields(cmdName)
|
|
||||||
|
|
||||||
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
||||||
stdout, _ := cmd.StdoutPipe()
|
stdout, _ := cmd.StdoutPipe()
|
||||||
|
@ -48,11 +47,25 @@ func ping(hostname string, count int) {
|
||||||
count, err = nbrerr.Read(oneByte)
|
count, err = nbrerr.Read(oneByte)
|
||||||
|
|
||||||
if (err != nil) {
|
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)
|
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.Write([]byte(string(oneByte)))
|
||||||
f.Flush()
|
f.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// spew.Dump(reflect.ValueOf(cmd.Process).Elem())
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue