diff --git a/random-output/main.go b/random-output/main.go index 97b6f35..78af4ae 100644 --- a/random-output/main.go +++ b/random-output/main.go @@ -14,5 +14,5 @@ func main() { // shellRAW("localhost", 5) // simpleProcess("ping -c 10 localhost") - ping("localhost", 10) + shell("ping localhost -c 5", 10) } diff --git a/random-output/shell.go b/random-output/shell.go index fe06f6e..3938b06 100644 --- a/random-output/shell.go +++ b/random-output/shell.go @@ -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()