SR has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am in a critical situation now, and to automate some process, i need to simulate keystrokes for a application running under Solaris/Linux. Is there any good way of doing it? Any help is greatly appreciated!

Replies are listed 'Best First'.
Re: Simulating Keystrokes in Solaris/Linux
by suaveant (Parson) on Dec 12, 2007 at 14:26 UTC
    Need more info.

    If it is a console program, Expect will do it, if it is a windowed app, I don't know.

    Either way, more info, such as what kind of app, what you are trying to accomplish (just input, input then reading output?) etc will go a long way in getting you a good answer.

                    - Ant
                    - Some of my best work - (1 2 3)

      Its a windowed program running under solaris
        Hi,

        This QA tool supports Perl scripting - it is on my list of things to try, haven't gotten to it yet:)

Re: Simulating Keystrokes in Solaris/Linux
by almut (Canon) on Dec 12, 2007 at 16:43 UTC

    In addition to the Perl solutions already suggested, there's also this nifty little (non-Perl) program xdotool.  Like X11::GUITest, it relies on the X server extension XTEST (pretty common these days — use xdpyinfo | grep -i xtest to check if available).

    It should be mentioned that you'll need an X development environment (header files) to build xdotool — those are typically distributed as X*-dev packages, to be installed in addition to the regular X server / Xlib packages.

    BTW, security is handled the normal X way (auth cookies, or whatever the X server is configured to use).

Re: Simulating Keystrokes in Solaris/Linux
by moritz (Cardinal) on Dec 12, 2007 at 14:41 UTC
    I guess that's not possible in the general case, due to security concerns.

    Imagine an admin who is logged in as a normal user but has an open root shell in a xterm. Every program that he runs the normal user could gain root privileges easily by sending the commands to the open root shell.

    BTW Vista had a similar bug, I hope they sorted it out by now...