0

I have a script which needs some kind of interaction from user to work properly. How do I pass custom commands from one terminal window to another ?

Let s say we have 2 terminals opened. /dev/ttys000 and /dev/ttys001, on the first one our interactive shell is working. Now commands like - help > /dev/ttys000 work fine, but custom commands which my script supports like - itIsNotABashCommand > /dev/ttys000 don t work at all, printing 'command not found'.

4ae1e1
  • 7,228
  • 8
  • 44
  • 77
DanoPlu
  • 279
  • 1
  • 16
  • I don't see how passing command from one terminal to another has anything to do with "command not found". – 4ae1e1 Dec 06 '15 at 14:06
  • Let me explain. On 1 terminal an interactive session is running. In this session you have some 'custom' commands acceptable only there. So now I would like to fire some 'custom' commands from another terminal or Java program, or even Bash script to manage my session and do some stuff there. Is it clear now ? :) Thanks for reply – DanoPlu Dec 06 '15 at 14:16
  • 1
    But wait, is it that simple? For instance we build a simple program in C which asks user about his name, we run the program in Terminal and it waits for user's input, and I want to interact with this simple session from another terminal window. Editing PATH is not a solution I m afraid. – DanoPlu Dec 06 '15 at 14:20
  • That's not a command. And no, unless you establish a named pipe, it's not possible. – 4ae1e1 Dec 06 '15 at 14:22
  • Could you give me any suggestions how do I execute something like customCommand > DifferentTerminalID then? – DanoPlu Dec 06 '15 at 14:26
  • As I said, establish a named pipe beforehand (or look at http://stackoverflow.com/a/593764/1944784 for redirecting standard streams after the fact, which may or may not work, I've never done anything like that). Otherwise, it's not possible. – 4ae1e1 Dec 06 '15 at 14:30
  • 1
    `help > /dev/ttys000` does not set the command `help` to be executed in the other terminal; it runs the command in the current shell, then sends the *output* to the other terminal. – chepner Dec 07 '15 at 02:16

1 Answers1

0

Maybe your system has this ioctl for

Faking input
       TIOCSTI   const char *argp
              Insert the given byte in the input queue.

In that case, see "Construct a command by putting a string into a tty".

Armali
  • 18,255
  • 14
  • 57
  • 171