How to program another terminal to output programmatically in C on Linux

I'm kind of new to Unix.

I want to have a small chat program that the source terminal uses for input, and call other output for output. I searched on the internet, but with no luck.


OK, to be more specific, I am writing a chat program over TCP / IP on a Mac in C. I want to separate input and chat messages on two different terminals. I can find resources on how to interact between processes, but I don't know how to call another terminal for output.

0
source share
1 answer

It is very unusual to spawn another terminal, as you seem to be doing. A cleaner approach would be to use a file (or named pipe) to get output from your chat program, then run tail -f (or another program to format the output correctly) on another terminal to display its contents. The first terminal will be used for input (possibly from stdin ), and the second terminal will receive tail output.

Command line example:

  • Launch the chat client by sending any output to a file called "output":

     $ ./client [parameters] > output 
  • In another terminal, display the output by reading from this file:

     $ tail -f output 

Remember that your chat program should be able to simultaneously process two different input sources (incoming messages from both the server and the user), possibly using select() .

+3
source

All Articles