linux - move stdout out of the console, in portable C -


the target application can used in "pipe" mode, means accepts input stdin, , can output stdout.

however, there risk of user making mistake, directing output stdout, without directing stdout towards "something" (a file, or consumer program). consequence, console screen gets garbaged displaying binary data (since default, stdout outputs screen).

bottom line : want avoid binary output displayed console, automatically. must done in portable c, , not depend on external script.

a few potential ways of doing :

1) possible detect stdout going console, in order redirect somewhere else instead ? (including /dev/nul). note code must portable, , work windows , linux (and bsd, opensolaris, etc.)

2) alternative : possible redirect stdout "somewhere else" (such /dev/nul) default without harming correct usage of program, redirecting stdout valid consumer process ?

on posix (e.g. linux , osx) system can use isatty function check if stdout goes console or else:

if (isatty(stdout_fileno))     printf("going console\n"); else     printf("standard output redirected or piped\n"); 

unfortunately there no portable way works on both posix systems , windows.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -