Quote:
Originally posted by majeed73
Thanks Perderabo for your reply, what I am sure about is that i have no clue about what you mean by saying your program seems to require tty input and how that would make a difference,
There are many ways that a program can set itself up to work with a tty but fail with file input. They are rather complex. But I will describe one of them.
By sending the correct ioctl()'s calls to the standard input (which is assumed to be a tty), the program can set the MIN > 0 and the TIME > 0. (exactly how to do this is documented under "man termio") Once that is done, the program can then issue a multi-char read system call. The editor vi works this way and you can't redirect your input into it either.
If The MIN is 1, then a read() will not return until at least one character has been typed. But if TIME is also 1, after a character arrives, the tty driver will wait up to one tenth of a second to see if another character arrives. If it does, a read() of 10 characters would get both characters returned to it. If it didn't, the read() would get just the one character. This is how a program can read a single keystroke. The "A" key will just send the character "A". But the home key will send a mult-character sequence. The program wants to read keystrokes, not characters.
But now redirect a file into our program. First the ioctl()'s will now fail. But some programs just ignore the error. Next the multi-byte read() occurs and it gets as many bytes as it specified. In your example you have the characters:
2
1
But there is an implied delay between those keystrokes. The program was depending on that delay. So it gets "21" when it just wanted "2".
This is just one way to depend on a tty for input. Read the "man termio" to see everything that the tty driver can offer to the program.