0

Using process substitution, we can get every lines of output of a command .

# Echoes every seconds using process substitution
while read line; do
   echo $line
done < <(for i in $(seq 1 10); do echo $i && sleep 1; done)

By the same way above, I want to get the stdout output of 'wpa_supplicant' command, while discarding stderr. But nothing can be seen on screen!

while read line; do
    echo $line 
done < <(wpa_supplicant -Dwext -iwlan1 -c${MY_CONFIG_FILE} 2> /dev/null)

I confirmed that typing the same command in prompt shows its output normaly.

$ wpa_supplicant -Dwext -iwlan1 -c${MY_CONFIG_FILE} 2> /dev/null

What is the mistake? Any help would be appreciated.

Ozawa Tomohiko
  • 157
  • 1
  • 1
  • 7
  • I don't know what's your problem here, but process substitution is absolutely pointless. Just pipe stdout to `while`. – 4ae1e1 Nov 16 '15 at 08:17

1 Answers1

0

Finally I found the answer here! The problem was easy... the buffering. Using stdbuf (and piping), the original code will be modified as below.

stdbuf -oL wpa_supplicant -iwlan1 -Dwext -c${MY_CONFIG_FILE} | while read line; do
    echo "! $line"
done

'stdbuf -oL' make the stream line buffered, so I can get every each line from the running process.

Community
  • 1
  • 1
Ozawa Tomohiko
  • 157
  • 1
  • 1
  • 7