Jump to content
Sign in to follow this  
Randolph

Copying text from command prompt

Recommended Posts

Randolph

Good Day,

I'm trying to copy text from a command prompt that could be minimized; have tried most of the suggestions like controlsend and controlgettext and can't seem to do it. Anyone with any help on this? Thanks.

Share this post


Link to post
Share on other sites
Malkey

If there are one or two points you missed in the help file under StdOutRead. And you have wasted enough time trying to modify the help file example to work the way you would like. Then, this example may be of help.

It was for me.

;
#include <Constants.au3>

$Command = @ComSpec & " /c dir /? "
;$Command = @ComSpec & " /c dir *.* /A:A /B /S /O:N "

$pid = Run($Command, "C:\Program Files\AutoIt3\AutoItX", @SW_HIDE, $STDERR_MERGED)

ProcessWaitClose($pid)

$output = StdoutRead($pid)

MsgBox(1, "output", $output)
;

Share this post


Link to post
Share on other sites
Randolph

Thanks for the replies. My problem is that the command prompt is an already existing window that I need to monitor. Any ideas? Thanks.

Share this post


Link to post
Share on other sites
Malkey

Good Day,

I'm trying to copy text from a command prompt that could be minimized; have tried most of the suggestions like controlsend and controlgettext and can't seem to do it. Anyone with any help on this? Thanks.

This is not an ideal solution but it works until anything better comes along.

"Quick Edit Mode" needs to be enabled. ( Right click title bar of prompt window > Properties > Options tab > Check Quick Edit Mode box. )

This script automates the highlight and right click on the highlight. This is what copies the text covered by the highlighted area to clipboard.

;
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

Local $sTitle = "Command Prompt" ; Text on title bar of window
Local $aWinPos, $sClipB

WinActivate($sTitle)
WinWaitActive($sTitle)
$aWinPos = WinGetPos($sTitle)

Send("{HOME}")
MouseClick("left", 3, 3, 1, 0)

;MouseClickDrag("left", 5, 8, $aWinPos[2], 8) ; Copy top line only
MouseClickDrag("left", 5, 8, $aWinPos[2], $aWinPos[3], 0)

MouseClick("right", $aWinPos[2] / 2, $aWinPos[3] / 2, 1, 0)

$sClipB = StringStripWS(ClipGet(), 2)
ConsoleWrite($sClipB & @CRLF)
MsgBox(0, "Copied Text", $sClipB)
;

Share this post


Link to post
Share on other sites
Randolph

get the ID of the window and hook into that.

How Would I do that?

Thanks for the suggestions; but winactivate won't work if the windows workstation is locked. I need something that can run in the background. I've tried the following; but can't seem to get it to work:

ControlFocus("[CLASS:ConsoleWindowClass", "", "")

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.