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

Hello, I have a perl script that wants to send a keystroke to end a process. I connect from an ubuntu system to windows with SSH and execute the script there but the keystroke is not sent ( I used Win32::GuiTest module ). Any ideas?

Replies are listed 'Best First'.
Re: perl ssh keystroke
by MidLifeXis (Monsignor) on May 23, 2016 at 11:04 UTC

    While the top level concept caught my interest, I can provide no feedback due to a couple of things that you may be able to help with:

    • Please provide a short working code example that demonstrates your issue. Include it in <code>...</code> tags for readability. This allows those interested in assisting the opportunity to execute the example to try to reproduce and help diagnose your issue.
    • Provide the output that you _do_ see, again, enclosed in <code>...</code> tags. How do you determine that the keystroke is not sent? Perhaps the response is being swallowed by the code. Perhaps the terminal emulation for the connection is not configured properly. Personally, I would guess that the issue has to do with buffering, but that is just a guess (see point one above).

    --MidLifeXis

Re: perl ssh keystroke
by atcroft (Abbot) on May 23, 2016 at 20:16 UTC

    First (probably stupid on my part) question, is your script currently able to interact with the window already?

    • If so, then I would start by looking at the Win32::GuiTest::SendKeys or Win32::GuiTest::SendRawKey methods (the former looks the simpler). (I would also look through the examples that are documented in the module as well.)
    • If not, then you have additional issues. (At that point, I would also be looking for other methods to control the script. :)

    Hope that helps.

      I don't think that the GuiTest will help me here. Basically I have a function that calls a getch that uninitiates the current process. That's what I am trying to achieve in perl ( simulate the keystroke ). When running the script in Windows it all goes well. I assume that when running it using ssh from ,let's say, ubuntu it fails to simulate the keystroke because ssh is not interactive.
        my $pid = open (PROCESS, " | $process_that_needs_ending > $output_filename) or die "message"; system(some_process_done_in_parralel); -> this spawned process needs to happen in the lifetime of PROCESS and afterwards it needs killing by keystroke
Re: perl ssh keystroke
by Marshall (Canon) on May 23, 2016 at 15:34 UTC
    I don't have a unix system to test with right now, but I do work with Windows often. It would be helpful to me if you could show how this does indeed work locally on the Windows box. If you can get the problem into: "hey, this works locally on Windows...example code..., now how can I do the same thing remotely from the unbuntu box? If it doesn't work locally, then typically that problem gets fixed first, then the remote problem from a different platform becomes easier to understand.
Re: perl ssh keystroke
by choroba (Cardinal) on May 25, 2016 at 08:08 UTC
    Crossposted at StackOverflow. It's considered polite to inform about crossposting, to prevent people not attending both sites from wasting their efforts hacking a problem already solved at the other end of the internet.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      I've read about crossposting and deleted the post from StackOverflow. Thx
        Then you haven't understood what you've read. I didn't say "crossposting is prohibited" or even "frowned upon", I said "it's considered polite to inform about it".

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,