简体   繁体   中英

How to invoke another terminal for output programmatically in C in Linux

I'm kind of new to the Unix environment.

I want to have a little chat program that the initial terminal is used for input, and invoke another terminal for output. I've been searching the web but without any luck.


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

It is rather unusual to spawn another terminal the way you seem to be doing. A cleaner approach would be to use a file (or a named pipe) to receive the output from your chat program, then run tail -f (or another program to properly format the output) on another terminal to display it's contents. The first terminal would be used for input (possibly from stdin ), and the second terminal would receive the output of tail .

A sample command-line usage would be:

  1. Run the chat client, sending any output to a file named "output":

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

     $ tail -f output 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM