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

前端 未结 1 1032
走了就别回头了
走了就别回头了 2020-12-12 06:25

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

相关标签:
1条回答
  • 2020-12-12 06:44

    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().

    0 讨论(0)
提交回复
热议问题