-
STDIN stdout
maybe someone can help me, I am writting a command line interface for an embedded device... kind of like a user shell, it just reads user input parses it, and spits back some output.
here is my problem, this CLI, needs to run over a serial port, a TCP socket, and a standard linux terminal trasparently... so instead of using send and recv, I am using read and write, which work great for TCP, and serial port, but when it comes to doing something like this on linux
read( 1, buff, sizeof(buff ));
I always get core dump.
does anyone know does linux store stdin, and stdout, as file descriptors ( not pointers )in global varibles???
thanks
-
I guess you could use fileno(stdin).
alex
-
>does anyone know does linux store stdin, and stdout, as file descriptors ( not pointers )in global varibles???
File descriptor of 'stdin' is 0 (not 1) and of 'stdout' is 1 (and ofcourse, 2 is the 'stderr'). You are trying to read from the output stream, which is incorrect. Change it to:
read(0, buff, sizeof(buff));