Make a file to act as tty with dup

c, linux, pipe, posix

Solution

Use a "pty" (Pseudo Terminal) as output. see this question for details.

Rachid Koucha wrote a lengthy article explaining the details how to work with ptys: Using pseudo-terminals (pty) to control interactive programs

Stop reading This text here just exists to stop the stupid SO algorithm to turn my answer into a comment. I hate it when software makes itself smarter than me :-(

Problem

Okay, so I have a problem. I must get the output of a program using the `execlp` and make the output go directly to a file. The problem is that the program only outputs certain information if it's running in a tty,(I guess it calls `isatty(3)`). Here is my code so far ``` void main(){ int fd = open("file", O_WRONLY | O_CREAT | O_TRUNC, 0755); close(1); dup(fd); execlp("program","program",NULL); close(fd); } ``` I don't want to use OS commands like `script` (which works) or so on. So the question is, how can I "trick" the program into thinking that it is writing into a tty?

Original source