Let's say I have one command window open, and it's running some Java application, regularly outputting text.

If I wanted to send a command to it, I could just type it in and press enter.

But how could I automate this? If there's some command to send a command to an open window, then I could put that into a .sh with a timer.

  • If I understand it correctly you want to send input to a terminal, right? – dr01 Aug 5 '15 at 9:10
  • does the window need to remain open? if not then screen can be used. it supports a -X stuff option to input to the screen session. i run lots of background stuff that way. edit: oh wait, -X stuff can input to a screen session that is open/connected. – Skaperen Aug 5 '15 at 9:15
  • @dr01 Yes, in some automated form – Quelklef Aug 5 '15 at 9:20
  • @Skaperen Which window? The original window shoud stay open, yes, the second terminal -- the one accessing it -- I don't care about. – Quelklef Aug 5 '15 at 9:21

You can run things under screen to automate stuffing input to applications. I have scripts in Python to make it easier to start a command in the background and stuff input (with control character encoding to let you do things like '\r' or '^c') to any screen sesssion (open or background).

  • you don't have to start the application in the background. just run screen manually, with the name you choose, in the window you want to see it run in. then in the automation you can run screen-in to stuff the input. – Skaperen Aug 5 '15 at 9:46
  • Hi, you edit your answer to include an example of how to do this? Additionally, is the apt-get name for screen-in just "scree-in"? Sorry, I'm new to Linux :) – Quelklef Aug 5 '15 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.