Reputation: 13195
I have a program that writes data to a file. Normally, the file is on disk, but I am experimenting with writing to /dev/stdout
. Currently, when I do this, the program will not exit until I press Ctrl-C . Is there a way for the program to signal that the output is done ?
Edit:
Currently, a disk file is opened via fopen(FILE_NAME)
, so I am now trying to pass in /dev/stdout
as FILE_NAME
.
Edit 2:
command line is
MY_PROGRAM -i foo -o /dev/stdout > dump.png
Edit 3:
It looks like the problem here is that stdout
is already open, and I am opening it a second time.
Upvotes: 1
Views: 2245
Reputation: 295649
The EOF condition on a FIFO (which, if you're piping from your program into something else, is what your stdout is) is set when no file handles are still open for write.
In C, the standard-library is fclose(stdout)
, whereas the syscall interface is close(1)
-- if you're using fopen()
, you'll want to pair it with fclose()
.
If you're also doing a separate outFile = fopen("/dev/stdout", "w")
or similar, then you'll need to close that copy as well: fclose(outFile)
as well as fclose(stdout)
.
Upvotes: 2