2

NOTE: The problem is based on GUI program, so ordinary pipe won't work, I need keep both program running.

Preparation: In Redhat or Ubuntu, two gnome-terminal opened, terminal A is running a script program, which can generate some string output; terminal B is running another program, which is waiting user input.

Goal: Make the output of the terminal A/program be the input of Terminal B automatically.

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. 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. If all commands come at the same time, B can only make response to the first one and ignore the rest.

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?

problem diagram

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
fgg1991
  • 65
  • 8
  • Write the output of P1 to file, then read the file from P2, maybe? – Reblochon Masque Sep 20 '18 at 01:13
  • well I considered this solution, but P2 can only take keyboard input or stdin as controller, I can't let it do reading operation......So I need to make the output of P1 flushed to P2 every time but not only one time when P1 terminated – fgg1991 Sep 20 '18 at 01:17
  • You often use Unix Domain Sockets for the fastest IPC on Linux. Also see [Which Linux IPC technique to use?](https://stackoverflow.com/q/2281204/608639), [Interprocess communication in Python](https://stackoverflow.com/q/6920858/608639), [Interprocess communication via Pipes](https://stackoverflow.com/a/43412558/608639), [Interprocess Communication via file](https://stackoverflow.com/q/11062444/608639), [Interprocess Communication in C++](https://stackoverflow.com/q/1343626/608639), etc. – jww Sep 20 '18 at 01:43
  • Possible duplicate of [Interprocess communication in Python](https://stackoverflow.com/q/6920858/608639). You often use Unix Domain Sockets for the fastest IPC on Linux. Also see [Which Linux IPC technique to use?](https://stackoverflow.com/q/2281204/608639), [Interprocess communication via Pipes](https://stackoverflow.com/a/43412558/608639), [Interprocess Communication via file](https://stackoverflow.com/q/11062444/608639), [Interprocess Communication in C++](https://stackoverflow.com/q/1343626/608639), etc. – jww Sep 20 '18 at 01:47

1 Answers1

0

In one way, I recommend changing the way to connect these terminals.

Or, you could try/dev/tty file.

/dev/tty is a special file, representing the terminal for the current process. So, when you echo 1 > /dev/tty, your message ('1') will appear on your screen. Likewise, when you cat /dev/tty, your subsequent input gets duplicated (until you press 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). I can't think of a good use for it, but there are similar files which are very useful for simple IO operations (e.g. /dev/ttyS0 is normally your serial port)

It does make your command to pass to the terminals, but I am not sure you could exec them with this way.

tianhua liao
  • 655
  • 5
  • 9