Created
September 29, 2019 17:52
-
-
Save wiless/59fd3d39c8f889e3a7f1e9b8040d8f2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"os/exec" | |
"strings" | |
) | |
//iperf3 -c 192.168.1.65 -u -i 1 -b 4000M --forceflush | |
func main() { | |
cmd := exec.Command("/usr/bin/iperf3", "-c", "192.168.1.101", "-u", "-i1", "-t5", "--forceflush") | |
fmt.Println("Executing .. : ", strings.Join([]string{"/usr/bin/iperf3", "-c", "192.168.1.101", "-u", "-i1", "-t5", "--forceflush"}, " ")) | |
cmdReader, err := cmd.StdoutPipe() | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err) | |
os.Exit(1) | |
} | |
scanner := bufio.NewScanner(cmdReader) | |
go func() { | |
for scanner.Scan() { | |
str := scanner.Text() | |
// fmt.Printf("%s\n", str) | |
strarray := strings.SplitAfter(str, " ") | |
fmt.Printf("\n Report : %#v", strarray) | |
} | |
}() | |
err = cmd.Start() | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "Error starting Cmd", err) | |
os.Exit(1) | |
} | |
err = cmd.Wait() | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "Error waiting for Cmd", err) | |
os.Exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment