6

When I run alsactl monitor, I see output as such when I adjust the volume:

card 0, #24 (2,0,0,PCM Playback Volume,0) VALUE
card 0, #24 (2,0,0,PCM Playback Volume,0) VALUE

However, when I try to redirect this to a file or a process with >, >>, or |, I see no output, and the output is not redirected.

What causes this behavior, and how can I fix it?


FYI, this is for a hack to force a broken left speaker to stay at 0:

alsactl monitor | \
while read; do
    amixer -D pulse sset Master 0,-
done

If someone knows a better way of doing this (e.g. how to lock a control so it can't be changed), that would be great!

4
  • use alsactl monitor |& less ..replace less with any other command you want..
    – heemayl
    May 31, 2015 at 13:58
  • @heemayl: That throws an error in sh, and doesn't work for me in bash. What is |& supposed to do?
    – Zaz
    May 31, 2015 at 15:33
  • that will redirect both stdout & stderr as stdin of the command on the right side of pipe....I have never used alsactl, my alsactl does not have a monitor option..reading your question my primary guess was that it might writing in stderr...that's why I suggest you to do that..
    – heemayl
    May 31, 2015 at 15:37
  • @heemayl: Ah, thanks, didn't know that. As it happens, it was outputting to stdout, but there was a buffering issue.
    – Zaz
    May 31, 2015 at 15:51

1 Answer 1

9

The problem is that since alsactl doesn't terminate until you forcefully terminate it, the buffered output cannot be written to the file, because this is something done after the command has terminated its execution.

You can force the stdout of alsactl to be line-buffered and hence to be redirected immediately after each line of output using stdbuf:

stdbuf -oL alsactl monitor > outputfile
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .