简体   繁体   English

使用一个终端将输入发送到另一终端?

[英]Using one terminal to send input to other terminal?

I'm a beginner in C programming and I'm trying to write a code to send the input from one terminal to another terminal in wich I'm running a program (I don't know if it makes any difference but it's a telnet program). 我是C编程的初学者,我正在尝试编写代码以将输入从一个终端发送到另一终端,直到我正在运行一个程序(我不知道它是否有什么区别,但这是一个telnet。程序)。 The reason for this is that often I'm writing a command to the program and it sends some text, making what I wrote so far impossible to change. 这样做的原因是,我经常向该程序编写命令,并且它发送一些文本,从而使到目前为止我写的内容无法更改。 My intention was running a program in a small terminal under the main one, and send the commands through this one, I've looked at many questions at stack overflow to write this program but it doesn't seem to work, so I decided to ask here what am I doing wrong? 我的意图是在主终端下的一个小终端中运行一个程序,并通过该终端发送命令,我在堆栈溢出时曾看过很多问题来编写此程序,但它似乎没有用,所以我决定问这里我在做什么错? Sorry if that's not an apropriate question for this site, but it is the best I know. 抱歉,这不是该网站的适当问题,但这是我所知道的最好的问题。 Here is my code: 这是我的代码:

(I'd also appreciate any sugestions you might have) (我也很感谢您提出的任何建议)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char command[1001];
    char px[1001 + 8 + 13 + 3] = "";
    char p1[8] = "echo | ";
    char p2[13] = " > /dev/pts/";
    char p3[3] = "";

    int term, compLimit, i;
    compLimit = 14;

    printf("Put terminal number here: ");
    scanf("%d", &term);
    sprintf(p3, "%s%d", p3, term);

    while(strncmp(px, "exit mudclient", compLimit))
    {
        for(i = 0; i < 1021; i++) px[i] = 0;
        scanf("%s", command);
        strcat(px, p1);
        strcat(px, command);
        strcat(px, p2);
        strcat(px, p3);
        system(px);
    }
    return 0;
}

It looks to me from your description of your problem that what you actually need is master ncurses library. 从您对问题的描述来看,我真正需要的是主ncurses库。 With it you will be able to separate output from input within a single terminal, and you will also gain full-featured input editing capabilities (with a scrollable command history). 有了它,您将能够在单个终端内将输出与输入分开,并且还将获得功能齐全的输入编辑功能(具有可滚动的命令历史记录)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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