I cannot redirect output to file

119 views Asked by At

I use specific program named lirc_monitor is used to monitoring pressed keys on the embedded ARM device. I wanna redirect all output to file but I'm stuck I spended ~2 hours to check every option what I found and... nothing! file all the time empty..

Maybe someone has any ideas? to verify this problem. Thank you.

-sh-3.2# lirc_monitor 
{lirc monitor}: 0000000000000000 00 CURSOR_DOWN MTK_IR

{lirc monitor}: 0000000000000000 00 CURSOR_DOWN MTK_IR

{lirc monitor}: 0000000000000000 00 CURSOR_DOWN MTK_IR

{lirc monitor}: 0000000000000000 00 CURSOR_DOWN MTK_IR

{lirc monitor}: 0000000000000000 00 CURSOR_DOWN MTK_IR

{lirc monitor}: 0000000000000000 00 CURSOR_DOWN MTK_IR
4

There are 4 answers

1
ti7 On

You can redirect the output stream with >

lirc_monitor > output.log

For more convenience, use tee, which will write to both the file and stdout

lirc_monitor | tee -a output.log

If > doesn't redirect the output (you still see the output with simply >), it's going to stderr, and you can redirect it with 2> filename directly or 2>&1 to join the stderr to stdout stream

lirc_monitor 2>&1 | tee -a output.log
3
Shirofuji On

Have you tried the using nohup

nohup lrc_monitor > lrc_monitor.log &

nohup - ignores hang up, probably needed because lrc_monitor seem to keep running until you stop it manually.

> lrc_monitor.log - tells the terminal to log the output to a file called lrc_monitor.log

& - tells the terminal to run your command in the background

1
Chris Dodd On

lirc_monitor normally outputs to stderr rather than stdout, so you need 2> to redirect its output. Eg:

lirc_monitor 2> lirc_monitor.log
0
jasko887 On

Ok I got help on russian forum this is translation:

"PS: I got burned and I made a smarter patch - now lirc_monitor clears buffers after each line by calling fflush(). Patched lirc_monitor_fflush, which can be parsed normally with a pipe:"

So I got patched binary file and I can without any problems redirect to log.

Problem resolved.