0

I want to append date and time before each line in a text log file in windows I run iperf command in cmd in windows 10. iperf.exe -c192.168.5.199 -u -t4 -i1 -f Kbytes -w1024k -b1024k >> client-log.txt

C:\iperf-2.0.9-win64\iperf-2.0.9-win64>iperf.exe -c192.168.5.199 -u -t4 -i1 -f Kbytes -w1024k -b1024k
------------------------------------------------------------
Client connecting to 192.168.5.199, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11484.38 us (kalman adjust)
UDP buffer size: 1024 KByte
------------------------------------------------------------
[  3] local 192.168.5.133 port 50929 connected with 192.168.5.199 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec   126 KBytes   126 KBytes/sec
[  3]  1.0- 2.0 sec   125 KBytes   125 KBytes/sec
[  3]  2.0- 3.0 sec   125 KBytes   125 KBytes/sec
......
......
......
......
......
......

Expected output

C:\iperf-2.0.9-win64\iperf-2.0.9-win64>iperf.exe -c192.168.5.199 -u -t4 -i1 -f Kbytes -w1024k -b1024k
------------------------------------------------------------
Client connecting to 192.168.5.199, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11484.38 us (kalman adjust)
UDP buffer size: 1024 KByte
------------------------------------------------------------
Wed Jan 27 11:44:26 UTC 2021 [  3] local 192.168.5.133 port 50929 connected with 192.168.5.199 port 5001
Wed Jan 27 11:44:26 UTC 2021 [ ID] Interval       Transfer     Bandwidth
Wed Jan 27 11:44:26 UTC 2021 [  3]  0.0- 1.0 sec   126 KBytes   126 KBytes/sec
Wed Jan 27 11:44:26 UTC 2021 [  3]  1.0- 2.0 sec   125 KBytes   125 KBytes/sec
Wed Jan 27 11:44:26 UTC 2021 [  3]  2.0- 3.0 sec   125 KBytes   125 KBytes/sec

My efforts

C:\iperf-2.0.9-win64\iperf-2.0.9-win64>iperf.exe -c192.168.5.199 -u -t4 -i1 -f Kbytes -w1024k -b1024k | echo %DATE% %TIME% >> client-log.txt

but its not adding date before each line it prints.

  • 1
    [1] iperf is not a PoSh command ... and you are piping its output to `echo` ... which is an alias for `Write-Output` ... and that does not accept pipeline input. ///// [2] the `%date%` stuff is for CMD.exe scripts ... it does not work that way in powershell. – Lee_Dailey Jan 27 '21 at 15:19
  • how will it work then ? – Jyoti Kumar Jan 28 '21 at 03:11
  • i downloaded iperf3 and used this >>> `iperf3 -c iperf.scottlinux.com -u -t4 -i1 -f KBytes -b1024 -T "$(Get-Date -Format 'ddd MMM dd HH:mm:ss yyyy')"` <<< and got lines like this >>> `Thu Jan 28 08:49:15 2021: [ 4] 0.00-1.00 sec 88.0 KBytes 87.9 KBytes/sec 11`. that bypasses most of powershell. if you need a different format, that would require a bit more PoSh code. [*grin*] ///// PS - i cannot use `-w1024K` ... it makes things hang for at least 8 minutes for me. – Lee_Dailey Jan 28 '21 at 14:52
  • @Lee_Dailey I am not getting append date. ##### C:\iperf-2.0.9-win64>cd C:\iperf-2.0.9-win64 && iperf.exe -c 192.168.5.199 -i1 -t4 -b1024k -T "$(Get-Date -Format 'ddd MMM dd HH:mm:ss yyyy')" `[ 3] 0.0- 1.0 sec 128 KBytes 1.05 Mbits/sec` – Jyoti Kumar Jan 28 '21 at 16:27
  • are you running that in a powershell console? i ran mine in ps5.1 on win10, 20h2. also, i ran iperf3 ... you seem to be running iperf2. have you tried updating to the current version? – Lee_Dailey Jan 28 '21 at 16:36
  • Thanks Lee, finally It worked. updaed iperf3 and powershel 5.1 in wondows 10 – Jyoti Kumar Jan 28 '21 at 16:53
  • `cd C:\iperf-3.1.3-win32 && iperf3.exe -c 192.168.5.199 -i1 -t4 -b1024k -T "$(%DATE% %TIME%)"` – Jyoti Kumar Jan 28 '21 at 16:53
  • you are welcome! glad to have helped a bit. [*grin*] – Lee_Dailey Jan 28 '21 at 17:31

0 Answers0