Jump to content

Copying text from command prompt


 Share

Recommended Posts

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)
;
Link to comment
Share on other sites

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)
;
Link to comment
Share on other sites

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", "", "")
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...