简体   繁体   English

如何使在一个终端中运行的程序的输出成为另一终端的输入?

[英]How to make the output of program running in one terminal be the input of another terminal?

NOTE: The problem is based on GUI program, so ordinary pipe won't work, I need keep both program running. 注意:该问题基于GUI程序,因此普通管道无法正常工作,我需要保持两个程序都运行。

Preparation: In Redhat or Ubuntu, two gnome-terminal opened, terminal A is running a script program, which can generate some string output; 准备工作:在Redhat或Ubuntu中,打开了两个gnome终端,终端A正在运行一个脚本程序,该程序可以生成一些字符串输出; terminal B is running another program, which is waiting user input. 终端B正在运行另一个程序,正在等待用户输入。

Goal: Make the output of the terminal A/program be the input of Terminal B automatically. 目标:使终端A /程序的输出自动成为终端B的输入。

The main challenge point is that, the program running in terminal B is beyond my control, it can only take some kind of specific user inputs via keyboard, I can not type any other pipe command while running it. 主要的挑战点是,在终端B中运行的程序是我无法控制的,它只能通过键盘接受某种特定的用户输入,运行时我不能键入任何其他管道命令。 Also, program B need some time to handle the command passed from program A, so if I have more than one command I need to keep both program RUNNING, but not like ordinary pipe: A generate series of command and terminated itself, all commands would be passed to B at the same time, B get input and response. 另外,程序B需要一些时间来处理从程序A传递来的命令,因此,如果我有多个命令,则需要使两个程序都保持运行状态,但与普通管道不同:A生成一系列命令并终止自身,所有命令都会同时传递给B,B得到输入和响应。 If all commands come at the same time, B can only make response to the first one and ignore the rest. 如果所有命令都同时出现,则B只能对第一个命令做出响应,而忽略其余命令。

Till now I have to copy the first program output and paste it into terminal B, is there any clever way to do link two terminal and make this operation automatically? 到现在为止,我必须复制第一个程序输出并将其粘贴到端子B中,是否有任何巧妙的方法来链接两个端子并自动执行此操作?

问题图

In one way, I recommend changing the way to connect these terminals. 我建议以一种方式更改连接这些端子的方式。

Or, you could try /dev/tty file. 或者,您可以尝试/dev/tty文件。

/dev/tty is a special file, representing the terminal for the current process. / dev / tty是一个特殊文件,代表当前进程的终端。 So, when you echo 1 > /dev/tty, your message ('1') will appear on your screen. 因此,当您回显1> / dev / tty时,您的消息('1')将出现在屏幕上。 Likewise, when you cat /dev/tty, your subsequent input gets duplicated (until you press Ctrl-C). 同样,当您使用/ dev / tty时,您的后续输入将重复(直到您按Ctrl-C组合键)。

/dev/tty doesn't 'contain' anything as such, but you can read from it and write to it (for what it's worth). / dev / tty并没有“包含”任何东西,但是您可以从中读取并写入(出于其价值)。 I can't think of a good use for it, but there are similar files which are very useful for simple IO operations (eg /dev/ttyS0 is normally your serial port) 我想不到它的好用,但是有一些类似的文件对于简单的IO操作非常有用(例如/ dev / ttyS0通常是您的串行端口)

It does make your command to pass to the terminals, but I am not sure you could exec them with this way. 它确实使您的命令传递到终端,但是我不确定您是否可以通过这种方式执行它们。

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

相关问题 在终端以不同的输出运行相同的程序 - Running same program in terminal with different output 如何让python程序向终端输入命令并从终端获取输出 - How to make a python program enter command to terminal and get output from terminal 如何从不同的终端向运行在linux终端窗口中的python程序的python程序提供raw_input,它们都在同一UNIX上运行 - How to supply raw_input to a python program running on a terminal window in linux from a different terminal, all running on same UNIX 如何让 YOLO output 成为另一个程序的输入? - How to make YOLO output to the input for another program? 如何将终端输出数据输入到python程序中? - How to get terminal output data into a python program? 如何让程序放弃对终端的控制? - How to make the program relinquish control of the terminal? Python:启动终端程序并在运行时解析其输出 - Python: start terminal program and parse its output while it's running 将接收键盘输入的 Python 程序的 output 发送到终端和文件 - Send output of Python program that receives keyboard input to terminal and to file 从终端 session 运行用户 Pythin 用户输入程序时出现问题 - Problem running a user Pythin user input program from a terminal session 在终端中运行 Python 程序时出错 - Error running a Python program in Terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM