How to redirect to stdout?

I have a UNIX application written in ansi C that writes data directly to a file. This file is specified by one of the argument parameters.

For testing purposes, I can use / dev / null for the file name, which actually redirects the output to nothing.

I would like to be able to redirect the output to stdout using a similar method. Is it possible? If so, how? I tried the following with no luck:

a.out -f / dev / ttys000

(where / dev / ttys000 is the tty specified in the 'w' list)

+4
source share
2 answers

/dev/stdout

+15
source

You can detect the string stdout argument, and then use the stdout file descriptor in C (1) http://en.wikipedia.org/wiki/File_descriptor

Or use / dev / stdout or / dev / fd / 1

If this is a β€œbuilt-in” function and not a temporary thing to test, you can use the C functions in the stdout file descriptor and not in the node device, since the C standard is a little more resilient than the POSIX imho standard.

+2
source

All Articles