The code you wrote works for me in a simple test program that does nothing. Remember that when you call execl, the process saves all old file descriptors. So no matter what you do when you call execl, it will be the same when loading a new binary. If you just want the output to go to the terminal, just make sure stdout is sent to the terminal.
If you want to do I / O with another program, it is useful to use popen (as mentioned in mgb). It will open a new process, configure the plumbing for you, call some version of exec and return a file descriptor that you can use for communication.
source share