0

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
shawn
  • 235
  • 3
  • 7
  • 1
    I think you need to be more specific if you want to get a meaningful answer to your question. For example, you could ask how to invoke another terminal, providing details of what desktop environment (KDE, Gnome, etc.) and terminal program you are using. Or you could ask what methods you could use to allow the two terminals to communicate with each other. (FIFO pipes, TCP/IP sockets, UNIX sockets, shared memory, etc.) Or you could pick one of those and ask where you can find resources showing you how to use it. Figure out what you need to know first and edit this question to reflect it. – David Z Aug 10 '10 at 02:42

1 Answers1

3

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

alecov
  • 4,882
  • 2
  • 29
  • 55