Python Forum
print the result of iperf log
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print the result of iperf log
#1
do anyone know how to print the result from the iperf log, test111.txt.
Do anyone have any idea on how to print the iperf log.
i wish to print like this:

Cycle: 0
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-10.00 sec 11.0 GBytes 9.46 Gbits/sec sender
[ 5] 0.00-10.00 sec 11.0 GBytes 9.46 Gbits/sec receiver
Cycle: 1
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-10.00 sec 11.3 GBytes 9.68 Gbits/sec sender
[ 5] 0.00-10.00 sec 11.3 GBytes 9.68 Gbits/sec receiver


import subprocess
import os
input11= 5
input_no=input("Please enter cycle: ")


if input_no =='':
    input_no=input11

for n in range(int(input_no)):

    command="iperf3 -c localhost --logfile test111.txt\n"
    p=subprocess.Popen(command, shell=True)
    print("Cycle:",n)
 
    p.wait()
Reply
#2
open as a file after for loop
and read line by line

to open file:
    with open('test111.txt') as fp:
        for line in fp:
            line = line.strip()
            print(line)
Reply
#3
hi Larzo60,
i have a question right now, how can i call function in a for loop.
i run a iperf command, and then wish to go to a function to print the text file. is there any idea about it.

My main code is to let user to type in the cycle, and then run iperf. When running iperf it will write al logfile, and i wish after running it can go to readfile function to put the related log information.

right now it occurs 'readfile' is not defined
# -*- coding: utf-8 -*-
import subprocess
import os
input11= 5
input_no=input("Please enter cycle: ")
# input_no= input("Enter a number: ")
if input_no =='':
    input_no=input11

for n in range(int(input_no)):
    #command="iperf3 -c 192.168.3.18 --logfile C:\\iperf-3.1.3-win64\n"
    command="iperf3 -c localhost --logfile test111.txt\n"
    p=subprocess.Popen(command, shell=True)
    print("Cycle:",n)
     
    p.wait()
    readfile()
	

def readfile():
    searchfile = open("test111.txt", "r")
    for line in searchfile:
        
        if "sender" in line: 
            #print("Cycle:\n", "=" *80)
            print (line)
        if "receiver" in line: 
            print (line)
        #count=+1
    searchfile.close()
Reply
#4
readfile is defined after your loop, so 'not defined' is the proper error.
remember python is an interpreter, so it evaluates code as read.

Moving the loop code after the function definition will work.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Saving the print result in a text file Calli 8 1,700 Sep-25-2022, 06:38 PM
Last Post: snippsat
  python read iperf log and parse throughput jacklee26 4 2,649 Aug-27-2022, 07:04 AM
Last Post: Yoriz
  print result in OUTPUT not in TERMINAL picasso 1 2,015 Apr-15-2020, 03:51 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020