Skip to content

Instantly share code, notes, and snippets.

@wiless
Created September 29, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiless/59fd3d39c8f889e3a7f1e9b8040d8f2f to your computer and use it in GitHub Desktop.
Save wiless/59fd3d39c8f889e3a7f1e9b8040d8f2f to your computer and use it in GitHub Desktop.
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