so I have a good and a bad news. The good news: I found the reason for your problem. The stream stdout is normally "line-buffered", but become block-buffered (e.g. 8Kb) when stdout is not connected to a terminal (for instance, when stdout is redirected to a pipe or a file)... This can be simply seen if you invoke factor as follows
The 'x' causes a message on stderr stream, and stdout to be flushed.
There are solutions to this problem, but those are not necessarily straightforward. That's the bad news. Basically, you have to let the child process think that it is attached to a pseudo-terminal. On Linux, this can be achieved using forkpty(). More info on this technique can be found here: rmathew: Terminal Sickness
If you want to play with bidirectional pipes, I suggest you to have a binary that you control (e.g. a shell script, or a C-program from you) where you can flush the stdout stream.
Is there any possibility that a Stream Read and Write queues will interchange messages of any kind. If so what are the different possiblites and under what circumstances ?
Thanks in advance. (4 Replies)
I am programming some data loader of oracle with unix c, when I find new data file, then read it to database and delete it. but one issue, if the file is in process of creating, not been closed yet. I will read zero or part of data content, this will cause problem. I want to know whether some unix... (2 Replies)
Hi Everyone,
Good day.
Scenario:
2 unix servers -- A (SunOS) and B (AIX)
I have an ftp script to sftp 30 files from A to B which happen almost instantaneously i.e 30 sftp's happen at the same time.
Some of these sftp's fail with the following error:
ssh_exchange_identification: Connection... (1 Reply)
Can you help me ?
I want to write a program ,which can open a input file (input.txt) and run as child process ,then write to output file (output.txt).......
char inFile="input.txt";
char outFile="output.txt";
int main(int argc, char **argv)
{
pid_t pid=1;
int no=0; // no. of... (5 Replies)
Hi,
I have file which contains information written in blocks (every block is different). Is it possible to read every block one by one to another file (one block per file).
The input is something like this
<block1>
<empty line>
<block2>
<empty line>
...
...
...
<block25>
<empty... (0 Replies)
Hi
I used this command:
mplayer http://host/axis-cgi/mjpg/video.cgi -user root -passwd root \
-cache 1024 -fps 25.0 -nosound -vc ffh264 \
-demuxer 3 -dumpstream -dumpfile output.avi It's ok but...
Video Playing is very fast! Why? Is it a synch problem?
What parameter I have to use for... (1 Reply)
I'm Unix. I'm looking at "df" on Unix now and below is an example. It's lists the filesystems out in 512-blocks, I need this in 4k blocks. Is there a way to do this in Unix or do I manually convert and how?
So for container 1 there is 7,340,032 in size in 512-blocks. What would the 4k block be... (2 Replies)
Hello,
I have a file like this:
FILE.TXT:
(define argc :: int)
(assert ( > argc 1))
(assert ( = argc 1))
<check>
#
(define c :: float)
(assert ( > c 0))
(assert ( = c 0))
<check>
#
now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
I have a script that takes 2 parameters (say) as mandatory
script1.sh a b
The 3rd parameter can be filename which it should process or it can come through a pipeline stream
The script should work both ways:
script1.sh a b filec
or cat filec | script1.sh a b
How to put logic in the... (1 Reply)
Hello,
Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row:
S02 Length Per
S02 7043 3.864
S02 54477 29.89
S02 104841 57.52
S03 Length Per
S03 1150 0.835
S03 1321 0.96
S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies
LEARN ABOUT LINUX
stderr
STDIN(3) Linux Programmer's Manual STDIN(3)NAME
stdin, stdout, stderr - standard I/O streams
SYNOPSIS
#include <stdio.h>
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
DESCRIPTION
Under normal circumstances every Unix program has three streams opened for it when it starts up, one for input, one for output, and one for
printing diagnostic or error messages. These are typically attached to the user's terminal (see tty(4) but might instead refer to files or
other devices, depending on what the parent process chose to set up. (See also the "Redirection" section of sh(1).)
The input stream is referred to as "standard input"; the output stream is referred to as "standard output"; and the error stream is
referred to as "standard error". These terms are abbreviated to form the symbols used to refer to these files, namely stdin, stdout, and
stderr.
Each of these symbols is a stdio(3) macro of type pointer to FILE, and can be used with functions like fprintf(3) or fread(3).
Since FILEs are a buffering wrapper around Unix file descriptors, the same underlying files may also be accessed using the raw Unix file
interface, that is, the functions like read(2) and lseek(2).
On program startup, the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2, respectively. The
preprocessor symbols STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO are defined with these values in <unistd.h>. (Applying freopen(3) to
one of these streams can change the file descriptor number associated with the stream.)
Note that mixing use of FILEs and raw file descriptors can produce unexpected results and should generally be avoided. (For the masochis-
tic among you: POSIX.1, section 8.2.3, describes in detail how this interaction is supposed to work.) A general rule is that file descrip-
tors are handled in the kernel, while stdio is just a library. This means for example, that after an exec(3), the child inherits all open
file descriptors, but all old streams have become inaccessible.
Since the symbols stdin, stdout, and stderr are specified to be macros, assigning to them is nonportable. The standard streams can be made
to refer to different files with help of the library function freopen(3), specially introduced to make it possible to reassign stdin, std-
out, and stderr. The standard streams are closed by a call to exit(3) and by normal program termination.
CONFORMING TO
The stdin, stdout, and stderr macros conform to C89 and this standard also stipulates that these three streams shall be open at program
startup.
NOTES
The stream stderr is unbuffered. The stream stdout is line-buffered when it points to a terminal. Partial lines will not appear until
fflush(3) or exit(3) is called, or a newline is printed. This can produce unexpected results, especially with debugging output. The
buffering mode of the standard streams (or any other stream) can be changed using the setbuf(3) or setvbuf(3) call. Note that in case
stdin is associated with a terminal, there may also be input buffering in the terminal driver, entirely unrelated to stdio buffering.
(Indeed, normally terminal input is line buffered in the kernel.) This kernel input handling can be modified using calls like tcse-
tattr(3); see also stty(1), and termios(3).
SEE ALSO csh(1), sh(1), open(2), fopen(3), stdio(3)COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-07-14 STDIN(3)