2

I'm attempting to redirect stderr from a mbuffer command to a file. It isn't working; the stderr output still appears on the screen and errors.txt is empty. My command is below:

$ raspivid -w 1280 -h 720 -o - | mbuffer -m 60M -f -o /tmp/temp_video.h264 2> errors.txt &
[2] 5278
in @ 1006 KiB/s, out @ 1006 KiB/s, 9292 KiB total, buffer   0% full^C
in @  0.0 KiB/s, out @  0.0 KiB/s,  9.9 MiB total, buffer  17% full^C

FYI, the stderr output I'm trying to redirect is "in @ 1006 KB/s...."

What did I do wrong? Thanks!

  • Try 2>&1 instead of 2>1 – ddnomad Mar 30 '17 at 4:16
  • Thanks for answering. I'm not trying to redirect stdout, only stderror. I'm currently doing 2> errors.txt. It should be 2>&1 errors.txt? – user2989813 Mar 30 '17 at 4:17
  • It looks like mbuffer might be thinking the redirect command is a mbuffer argument..? – user2989813 Mar 30 '17 at 4:24
  • well, you might try prepending -- before 2> then. It's an options end delimiter that works with most of CLI tools. Let me know whether it helps. – ddnomad Mar 30 '17 at 4:27
  • It says "mbuffer: fatal: unknown option "--"" if I do mbuffer -t -m 80M -f -o /tmp/temp_video.h264 -- 2>&1 test.txt & – user2989813 Mar 30 '17 at 4:30
4

You didn't do anything wrong, mbuffer reopens /dev/tty if it can't read from its standard error, defeating your redirection.

You can use the -q option to disable the status output. According to the documentation, you could use -l to log the status to a file with

mbuffer -m 60M -f -o /tmp/temp_video.h264 -l errors.txt &

but the status log is buggy: it always goes to standard error, not the log.

Here's how to fix this.

  1. Download the package source

    apt-get source mbuffer
    
  2. Add a patch (this requires the quilt package)

    cd mbuffer-20161115
    quilt new 13-status-log.patch
    quilt add mbuffer.c
    
  3. Edit mbuffer.c, and change line 461 (in Debian 8) or 472 (in Debian 9) to

    nw = write(Log,buf,strlen(buf));
    
  4. Store the patch

    quilt refresh
    
  5. Rebuild the package (this requires the dpkg-dev and devscripts packages)

    dch -n "Fix the status log to honour the -l option."
    dch -r ignored
    dpkg-buildpackage -us -uc
    

    (if dpkg-buildpackage complains about missing dependencies, install them and try again)

  6. Install the updated package

    sudo dpkg -i ../mbuffer_*-?.1_*.deb
    
  • This patch worked like a charm. I can confirm that this one-line change fixes the issue that -l wasn't logging any statuses. – user2989813 Mar 30 '17 at 13:28
0

I am the author of mbuffer, and just want to point out that the status log is not buggy. The intention was always to avoid logging status messages to the log, as it spoils the log and makes it unreadable, unless the user explicitly asks for it.

This is done, by raising the verbosity to level 4 with "-v 4".

As the default behavior causes confusion and there is also the option -Q to suppress status messages in the log, I am considering to include status messages in the log in a future release also at verbosity level 3.

Regards,

Thomas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.