Joshua Berry
Joshua Berry

Reputation: 2330

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 filename, which effectively redirects the output to nothing.

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

a.out -f /dev/ttys000

(where /dev/ttys000 was the tty specified by a 'w' listing)

Upvotes: 4

Views: 2618

Answers (2)

Aiden Bell
Aiden Bell

Reputation: 28386

You could detect the string "stdout" argument and then use the stdout filehandle in C (1) http://en.wikipedia.org/wiki/File_descriptor

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

If this is a 'built-in' feature rather than a temporary thing for testing, you might want to use the C functions on the stdout file descriptor rather than the device node as the C standard is a bit more hardy than the POSIX standard imho.

Upvotes: 2

laalto
laalto

Reputation: 152787

/dev/stdout

Upvotes: 15

Related Questions