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.
| [reply] [Watch: Dir/Any] [d/l] |
Although this is very cool, it does not help me in the case since I am trying to capture content in existing console windows.
| [reply] [Watch: Dir/Any] |
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.
| [reply] [Watch: Dir/Any] |
It is unclear to me what you're trying to do - are you trying to capture text that's already sitting in the console window when your script starts, or are you trying to run a command from inside your perl script and then read what the command spit out to the screen? Note that the first of those two is much more difficult than the second.
Also, if you're trying to capture text already sitting on the console, is your perl script attempting to read its own console, or someone else's? The first of those two tasks is much easier.
--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/;
map{y/X_/\n /;print}map{pop@$_}@/for@/
| [reply] [Watch: Dir/Any] [d/l] |
trying to capture text that's already sitting in the console window. I am trying to read someone else's console window.
| [reply] [Watch: Dir/Any] |