如何调用另一个终端输出编程在Linux下C [英] How to invoke another terminal for output programmatically in C in Linux

查看:213
本文介绍了如何调用另一个终端输出编程在Linux下C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点新Unix环境。

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,更具体,我写了TCP / IP在Mac上一个聊天程序C.我想输入和聊天消息的输出在两个不同的终端分开。我可以找到如何在进程间通信的资源,但我不知道如何调用另一个端子输出。

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.

推荐答案

这是相当不寻常的产卵另一端,你似乎在做的方式。一个清洁的方法是使用一个文件(或命名管道)接收来自您的聊天程序的输出,然后运行尾-f (或其他程序才能正常格式化另一终端上输出),以显示它的内容。第一终端将用于输入(可能来自标准输入),第二终端将获得尾的输出

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. 运行聊天客户端,发送任何输出到一个名为输出:

  1. Run the chat client, sending any output to a file named "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 handle two different sources of input simultaneously (incoming messages both from the server and from the user), probably using select().

    这篇关于如何调用另一个终端输出编程在Linux下C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆