Find the answer to your Linux question:
Results 1 to 8 of 8
Hi I have a program that receive user input. I want to run this program automatically without user interaction, and in order to do that I need to simulate key ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8

    How can I simulate key strokes events in other processes in linux?


    Hi
    I have a program that receive user input.
    I want to run this program automatically without user interaction, and in order to do that I need to simulate key events.
    How can I do such a thing?

    The program I am running is partly java and partly shell.

    The shell part is easily done by using:
    ./prog.sh <parameters (Parameters being a file containing parameters)
    But the java doesn't work similarly.

    Thanks
    Ron

  2. #2
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    if your program reads from stdin it should work.

  3. #3
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8

    Doesn't work in a multy threaded application

    Hi
    Thank you for your response
    The java program I am trying to run automatically open a several threads.

    I tried it on a simple basic jar and it did work, but in a case of a multithreaded environment it doesn't.

  4. #4
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    I can't see why that shouldn't work either. Of course you cannot dispatch stdin input in multithreading, but that just means you need a single threaded dispatcher who distributes the commands properly.

    EDIT: well, thinking about it you can even do that but you would have to replicate the input stream for each worker such that they don't "eat" each others tokens from stdin. anyway it would be quite odd and can be exploited drastically.

  5. #5
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    I'm not sure I fully understand your suggestion, how can I distribute it to threads?

    Let me point out that I am not sure how the application I am trying to automatically run is implemented, I do know that it got a console and gui mode (I am working on the console mode) and therefore I assume that these different panels are seperate threads.

    When running it, I receive one input request at a time.

    Thanks
    Ron

  6. #6
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    oh, you have no source code. well, that's troublesome. plain theoretical it would be something like piping either all or some of the stdin to logical workers inside the application, thus creating kind of a ESB.

    how do you know that there are multiple threads? doing stuff with a blackbox is always a bit nasty and troublesome. so you may wanna try decompiling the java bytecode using jadclipse or similar projects to get a better understanding of how it works?

  7. #7
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8

    Found the solution

    Hi
    Thanks for your assistance
    I found the solution in a unix command called "expect"

  8. #8
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    Oh, nice. Didn't know that. Added to bookmarks. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •