Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatted output cannot be piped #28

Closed
yberreby opened this issue Jun 30, 2015 · 7 comments
Closed

formatted output cannot be piped #28

yberreby opened this issue Jun 30, 2015 · 7 comments

Comments

@yberreby
Copy link

bmon -o format > file.txt creates an empty file. It is not possible to pipe the output of the program to a file (because of curses, I presume); I ran into this when trying to read the output of bmon from a parent process.

@tgraf
Copy link
Owner

tgraf commented Jun 30, 2015

I believe this has already been fixed. Curses used to be initialized for formatted output but this is no longer the case. What you describe works for me.

@yberreby
Copy link
Author

I have version 3.6 on OS X, installed with homebrew. I'll try building from source.

@yberreby
Copy link
Author

Still doesn't work with a fresh clone. Any idea why?

yohai@imac-5k ~/code/software/bmon$ bmon -o format
lo0 44484079 44484079 629458 629458
en0 248662754 38887010 296994 251607
en1 0 0 0 0
en2 0 0 0 0
en3 0 0 0 0
bridge0 0 342 0 1
^C
yohai@imac-5k ~/code/software/bmon$ bmon -o format > foo.txt
^C
yohai@imac-5k ~/code/software/bmon$ ls -lrt
total 984
drwxr-xr-x   3 yohai  staff     102 30 jui 12:05 m4
-rw-r--r--   1 yohai  staff    5402 30 jui 12:05 configure.ac
-rwxr-xr-x   1 yohai  staff      52 30 jui 12:05 autogen.sh
-rw-r--r--   1 yohai  staff    1587 30 jui 12:05 README.md
-rw-r--r--   1 yohai  staff     619 30 jui 12:05 NEWS
-rw-r--r--   1 yohai  staff     143 30 jui 12:05 Makefile.am
-rw-r--r--   1 yohai  staff    1023 30 jui 12:05 LICENSE.MIT
-rw-r--r--   1 yohai  staff    1192 30 jui 12:05 LICENSE.BSD
-rw-r--r--   1 yohai  staff       0 30 jui 12:05 ChangeLog
-rwxr-xr-x   1 yohai  staff  262681 30 jui 12:05 configure
-rw-r--r--   1 yohai  staff   49976 30 jui 12:05 aclocal.m4
drwxr-xr-x   8 yohai  staff     272 30 jui 12:05 build-aux
-rw-r--r--   1 yohai  staff   25532 30 jui 12:05 Makefile.in
drwxr-xr-x   6 yohai  staff     204 30 jui 12:05 man
drwxr-xr-x   6 yohai  staff     204 30 jui 12:05 include
drwxr-xr-x   6 yohai  staff     204 30 jui 12:05 examples
-rwxr-xr-x   1 yohai  staff   35180 30 jui 12:05 config.status
-rw-r--r--   1 yohai  staff   55532 30 jui 12:05 config.log
-rw-r--r--   1 yohai  staff   25779 30 jui 12:05 Makefile
drwxr-xr-x  52 yohai  staff    1768 30 jui 12:05 src
-rw-r--r--   1 yohai  staff       0 30 jui 12:07 foo.txt
yohai@imac-5k ~/code/software/bmon$

I'm running OS X 10.10.2 (Yosemite).

@tgraf
Copy link
Owner

tgraf commented Jun 30, 2015

This seems to be OS X specific then. Works fine on Linux:

[tgraf@lsx bmon]$ src/bmon -o format > l
^C
[tgraf@lsx bmon]$ wc -l l
262 l

Can you try the following?
bmon -o format:stderr 2> foo.txt

@yberreby
Copy link
Author

bmon -o format:stderr 2> foo.txt produces a output file with the data, it works.

@tgraf
Copy link
Owner

tgraf commented Jun 30, 2015

This may be related to OS X buffering stdout which delays writing to stdout immediately. You may have to use unbuffer or stdbuf if you want to use stdout. Just a guess though.

@yberreby
Copy link
Author

The problem was indeed caused by buffering - unbuffer solved it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants