0

Sorry for bad english.

I'm trying to determine whether iperf works or not.

so I decide to use cut and I found that the cut worked properly in normal result, but did not work when there was an error in the result.

Here is the example.

(Normal result of IPERF)
$iperf3 -c 192.168.1.100 -t 1 --connect-timeout 1000
Connecting to host 192.168.1.100, port 5201
... 

and

(Normal result of IPERF with cut)
$iperf3 -c 192.168.1.100 -t 1 --connect-timeout 1000|head -1|cut -d ' ' -f2
to

It works perpectly when there's no error

But if there is an error in the results

(Error result of IPERF)
$iperf3 -c 192.168.1.150 -t 1 --connect-timeout 1000
iperf3: error - unable to connect to server: Connection timed out

then

(Normal result of IPERF with cut)
$iperf3 -c 192.168.1.150 -t 1 --connect-timeout 1000|head -1|cut -d ' ' -f2
iperf3: error - unable to connect to server: Connection timed out

I expected 'error' as an result but it just shows everything.

I wonder what did I miss and How can I get proper result.

SW L
  • 1
  • The error is written to `/dev/stderr` while the standard output is written to `/dev/stdout`. The pipeline is only processing `/dev/stdout` and hence will not affect the output of `/dev/stderr` – kvantour May 09 '22 at 07:57
  • Does this answer your question? [Confused about stdin, stdout and stderr?](https://stackoverflow.com/questions/3385201/confused-about-stdin-stdout-and-stderr) and [Redirect stderr and stdout in Bash](https://stackoverflow.com/q/637827/8344060) – kvantour May 09 '22 at 07:59
  • The proper way to handle this error would be: `$iperf3 -c 192.168.1.100 -t 1 --connect-timeout 1000 || echo "There was an error"` – kvantour May 09 '22 at 08:05
  • Thx for the comment! I guess you shown way to me! – SW L May 09 '22 at 08:14
  • OMG Why I didn't think of || instead of that harsh work. you saved my day. Thank you – SW L May 09 '22 at 08:19

0 Answers0