Python 如何将 Iperf 结果保存在输出文件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25702196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to save Iperf result in an output file
提问by Rakhee Tiwari
I am running iperf between a set of hosts that are read from a txt file, here's how I am running it:
我在一组从 txt 文件中读取的主机之间运行 iperf,这是我运行它的方式:
h1,h2 = net.getNodeByName(node_id_1, node_id_2)
net.iperf((h1, h2))
It runs well and displays the results. But, I want to save the output of iperf result in a separate txt file. Does anyone know how I can apply it on the above code?
它运行良好并显示结果。但是,我想将 iperf 结果的输出保存在一个单独的 txt 文件中。有谁知道我如何将它应用于上述代码?
回答by Paolo
Do you already try:
您是否已经尝试过:
--output test.log
--输出test.log
(in newer versions --logfile)
(在较新版本中--logfile)
or using
或使用
youriperfexpr > test.log
youriperfexpr > test.log
回答by Taylor
I had this problem as well. Although the manpage specifies "-o" or "--output" to save your output to a file, this does not actually work.
我也有这个问题。尽管联机帮助页指定“-o”或“--output”将输出保存到文件,但这实际上不起作用。
It seems that this was marked as "WontFix": https://code.google.com/p/iperf/issues/detail?id=24:
似乎这被标记为“WontFix”:https: //code.google.com/p/iperf/issues/detail?id =24:
Looks like -o/--output existed in a previous version but in not in the current version. The consensus in yesterday's meeting was that if --output existed then we should fix it, otherwise people should just use shell redirection and we'll mark this WontFix. So, WontFix.
看起来 -o/--output 存在于以前的版本中,但不存在于当前版本中。昨天会议的共识是,如果 --output 存在,那么我们应该修复它,否则人们应该使用 shell 重定向,我们将标记这个 WontFix。所以,WontFix。
So maybe just use typescript or ">test.log" as suggested by Paolo
所以也许只是按照Paolo 的建议使用 typescript 或 ">test.log"
回答by user3107629
In order to store the results of iperf test in a file , add | teefollowed by the filename.txt to your command line for example :
为了将 iperf 测试的结果存储在一个文件中,添加| tee后跟 filename.txt 到您的命令行,例如:
iperf -c ipaddress -u -t 10 -i 1 | tee result.txt
iperf -c ipaddress -u -t 10 -i 1 | 开球结果.txt
回答by Anamort
I think the answer is given by Chiara Contoli in here: iperf result in output file
我认为 Chiara Contoli 在这里给出了答案:iperf result in output file
In summary:
总之:
h1.cmd('iperf -s > server_output.txt &')
h2.cmd('iperf -t 5 -c ', h1.IP() + ' > client_output.txt &')
回答by tgudtk
Since you are running it on python, another method to save the result is to use popen:
由于您在 python 上运行它,另一种保存结果的方法是使用 popen:
popen( '<command> > <filename>', shell=True)
For example:
例如:
popen('iperf -s -u -i 1 > outtest.txt', shell=True)
You can check this for further information:
您可以查看此以获取更多信息:
https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#popen
https://github.com/mininet/mininet/wiki/Introduction-to-Mininet#popen
回答by K.Vladimir
If you need to save a file in the txt format. On the client machine run cmd(adm) and after that you need to write this:
如果需要将文件保存为txt格式。在客户端机器上运行 cmd(adm) ,然后你需要这样写:
cd c:\iperf3 iperf3.exe -c "you server address" -p "port" -P 10 -w 32000 -t 0 >> c:\iperf3\text.txt
cd c:\iperf3 iperf3.exe -c “你的服务器地址” -p “端口” -P 10 -w 32000 -t 0 >> c:\iperf3\text.txt
(-t 0) - infinity On the client machine, you will see a black screen in cmd. It's normal. You will see all the process in the server machine. After your test, on the client machine in cmd need push ctrl+ c and after (y). Your file in directory c:\iperf3\text.txt after that collect all information about this period. If you push close in cmd this file text.txt will be empty.
(-t 0) - infinity 在客户端机器上,您将在 cmd 中看到黑屏。这是正常的。您将在服务器机器中看到所有进程。经过您的测试,在 cmd 中的客户端机器上需要按 ctrl+ c 和 after (y)。之后您在目录 c:\iperf3\text.txt 中的文件收集有关此时期的所有信息。 如果您在 cmd 中按下关闭,则此文件 text.txt 将为空。
Recommended open this file in NotePad or WordPad for the correct view.
建议在 NotePad 或 WordPad 中打开此文件以获得正确的视图。

