Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Capturing the text in a Console Window

by BrowserUk (Patriarch)
on Oct 13, 2005 at 14:30 UTC ( [id://499913]=note: print w/replies, xml ) Need Help??


in reply to Capturing the text in a Console Window

Assuming you have two Command windows running. One, currently idle (hence the regex '^command Prompt$'), that you wish to capture whatever is in it's buffer, and the other in which you will invoke this script (which will fail to match the regex because it will have the title text 'Command Prompt - yourname.pl' or similar).

This will capture the contents of the idle sessions buffer and print on the console where you run this script. If you have multiple idle windows, then it will capture and dump them all. Adjust the regex to select the appropriate window.

#! perl -slw use strict; use Win32::GuiTest qw[ FindWindowLike SendKeys SetForegroundWindow ]; use Win32::Clipboard; my $clip = Win32::Clipboard(); for my $w ( FindWindowLike( 0, '^Command Prompt$', 0, 0, 0 ) ) { SetForegroundWindow( $w ); SendKeys( '%{SPC}ES%{SPC}Ey' ); print $clip->Get(); }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Capturing the text in a Console Window
by slloyd (Hermit) on Oct 13, 2005 at 16:40 UTC

      It will/does capture content of existing (win32) console windows. It only requires you to specify a regex to match the titlebar of the existing console window and it will capture whatever is currently in the buffer (displayed and scrolled off if the buffer is larger than the screen).

      If this is not what you require, then perhaps you could clarify what you are after?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://499913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-23 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found