comp.unix.programmer

Re: ISO C libs with character EOF; Terminal with parent and child process


wy , dans le message
<12860744.552.1318108707588.JavaMail.geo-discussion-forums_at_prmr13>, a
?crit?:
> If I type a string that ends with '\n', it operates as excepted;
> If I type a newline(immediately after '\n') that consists and only
> consists of EOF, it exits as excepted;
> But if I type a string that ends with EOF, it operates as if I typed a
> '\n', and so it echoes, the only difference is that it doesn't change to a
> new line.
> So, why it operates differently when encounters a newline that consists
> and only consists of EOF and a newline that starts with a normal character
> and ends with EOF?
I believe you are confusing two meanings for the EOF acronym.
There is an EOF constant in standard C, which is the special code that the
stdio input functions return when they encounter what they believe is the
end of file or a read error. This is usually -1, and in particular is not
equal to any character.
There is an EOF key associated to the terminal. When the terminal is in
"cooked mode", keys that are typed are not transmitted to the process
reading from it immediately. Instead, they are fed to a rudimentary line
editing system that allows to correct with backspace, etc. The LF character
causes the current contents of the line editing buffer to be sent to the
reading process, including the LF character itself. The EOF key does the
same thing, except it is not added to the buffer.
So if you type "hello<LF>", the process reads "hello\n", while if you type
"hello<EOF>", the process reads "hello".
The EOF key is called like that because if you type it when the line editing
buffer is empty, the reading process will read 0 bytes, and that is usually
interpreted as the end of the stream.
> It must have something to do with "line buffered", but I cannot understand.
"Line buffered" usually refers to the output buffer of a stdio stream, not
input. That has nothing to do with your problem.
> After invoking popen(), is the terminal associated with both stdins,
> stdouts, and stderrs of the parent process and the child process?
Well, obviously not, that is the whole point of popen: to have either the
standard input or standard output of the process you start connected to a
pipe, itself connected to a stream to the running process. The other one is
unchanged, as is stderr.




Written by Nicolas George 08/10/2011 22.15.00
Check some pics on this site!
23/05/2012 22.34.12