How to get the text information on the CMD window?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zhainv2013
Posts: 23
Joined: 24 Apr 2019, 12:16

How to get the text information on the CMD window?

29 Dec 2020, 11:30

1. How to get the text information on the CMD window?

2. When the CMD window is hidden (minimized), how to get the text information on the CMD window?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to get the text information on the CMD window?

29 Dec 2020, 21:11

I'm sure there's a better way. This is what you might call "the lazy way".

Code: Select all

#IfWinExist ahk_exe cmd.exe
F3::
Clipboard =
WinActivate, ahk_exe cmd.exe
Send !{Space}es!{Space}ey
ClipWait, 2
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else MsgBox, 64, Results, %Clipboard%
Return
#IfWinExist
zhainv2013
Posts: 23
Joined: 24 Apr 2019, 12:16

Re: How to get the text information on the CMD window?

29 Dec 2020, 22:03

Is there a way to complete the operation in the background without interfering with the front desk?
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: How to get the text information on the CMD window?

29 Dec 2020, 22:10

maybe something like this :

Code: Select all

Run %comspec% /c "ping.exe www.google.com -n 1 > %A_Temp%\ping.txt",, Hide
FileRead,Ping,%A_Temp%\ping.txt
RegExMatch( Ping, "time=(.*)ms", Ping )
If (Ping1>100)
     MsgBox, 16, Alert, %Ping1%
Else MsgBox, 64, Ping Time, %Ping1%
https://autohotkey.com/board/topic/42649-reading-cmd-command-prompt-text/
zhainv2013
Posts: 23
Joined: 24 Apr 2019, 12:16

Re: How to get the text information on the CMD window?

29 Dec 2020, 22:29

I tried, but it didn't work. Is it because my network can't access Google directly?
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: How to get the text information on the CMD window?

29 Dec 2020, 23:40

zhainv2013 wrote:
29 Dec 2020, 22:29
I tried, but it didn't work. Is it because my network can't access Google directly?
try with this one :

Code: Select all

Run %comspec% /c "ping.exe www.google.com -n 1 > %A_Temp%\ping.txt",, Hide
Sleep, 1000
FileRead,Ping,%A_Temp%\ping.txt
MsgBox, % Ping
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to get the text information on the CMD window?

30 Dec 2020, 01:30

Spark wrote:
29 Dec 2020, 22:10
maybe something like this :

Code: Select all

Run %comspec% /c "ping.exe www.google.com -n 1 > %A_Temp%\ping.txt",, Hide
FileRead,Ping,%A_Temp%\ping.txt
RegExMatch( Ping, "time=(.*)ms", Ping )
If (Ping1>100)
     MsgBox, 16, Alert, %Ping1%
Else MsgBox, 64, Ping Time, %Ping1%
https://autohotkey.com/board/topic/42649-reading-cmd-command-prompt-text/
What about to pipe the output to the clipboard instead of a file?
url := "www.google.com"
Run % comspec " /c ping.exe " . url . " -n 1 | clip",, Hide
ClipWait
MsgBox % clipboard
Untested.
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: How to get the text information on the CMD window?

30 Dec 2020, 03:23

BoBo wrote:
30 Dec 2020, 01:30
What about to pipe the output to the clipboard instead of a file?
url := "www.google.com"
Run % comspec " /c ping.exe " . url . " -n 1 | clip",, Hide
ClipWait
MsgBox % clipboard
Untested.
Briliant :clap: :clap:
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: How to get the text information on the CMD window?

30 Dec 2020, 05:42

with CLIP

Code: Select all

clipboard=
url := "www.google.com"
Runwait, %comspec% /c ping %url% -n 3 | clip,, Hide
ClipWait,,1
MsgBox % clipboard
return
from user @teadrinker
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84266&sid=eff012cadb7a851b2c18f5f03b68408f
I like to see the streaming output in a GUI

Code: Select all

;-------- saved at 星期五 十二月 2020-12-11  17:36 UTC --------------
;- Hide command console when using RunWaitOne() example / from user teadrinker
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84266&sid=eff012cadb7a851b2c18f5f03b68408f
;------------------------------------------
;cmdx:="dir"
cmdx:="ping autohotkey.com -n 4"
;----- FOR TEST youtube-dl.exe-------------------------
;cmdx=youtube-dl -U  ;- update youtube-dl.exe
;cmdx=youtube-dl -h  ;- HELP   youtube-dl.exe
;------------------------------------------------------
;============== GUI ===========
#warn
#noenv
name1:="Youtube-dl_TEST"
global name1 
CPX:="cp" . DllCall("GetOEMCP", "UInt")        ;- get CODEPAGE e.g. CP850
setworkingdir,%a_scriptdir%
Gui,1:default
Gui,1: -DPIScale 
Gui,1:Color,Black,Black                        ; GUI black   / EDIT is BLACK
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;- maybe change fontsize
;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
if (wa=3840)
 Gui,1:Font,s12 cYellow,Lucida Console
;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
else if (wa=1920)
 Gui,1:Font,s10 cYellow,Lucida Console
else
 Gui,1:Font,s8 cYellow,Lucida Console
;=============================================================
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*70)/xx,h:=(ha*60)/xx
Gui, Add, Edit, x%x%   y%y%  w%w% h%h% 
x:=(wa*1)/xx,y:=(ha*63)/xx,w:=(wa*65)/xx,h:=(ha*6)/xx
Gui, Add, Edit, x%x%   y%y% w%w%  h%h% vED2,%cmdx%           ;- add CMDx command above or type commands here
x:=(wa*67)/xx,y:=(ha*63)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui,add,button, x%x%  y%y% w%w%  h%h% gA0, <START
x:=(wa*67)/xx,y:=(ha*66)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui,add,button, x%x%  y%y% w%w%  h%h% gClear, <CLEAR
x:=(wa*2)/xx,y:=(ha*2)/xx,w:=(wa*75)/xx,h:=(ha*75)/xx
Gui, Show,x%x% y%y% w%w% h%h%,%name1%
gosub,a0
return
;-------------------------
Guiclose:
Exitapp
;==============================
AddOutputInGui(output) {
   Control, EditPaste, %output%`r`n, Edit1,%name1%
}
;-------------------------
A0:
Gui,1:submit,nohide
ed2a:="cmd /c " . ed2
CmdRet(ED2a, Func("AddOutputInGui"),CPX)
return
;-------------------------
CLEAR:
Guicontrol,1:,ED2,
return
;=========================================================
CmdRet(sCmd, callBackFuncObj := "", encoding := "CP0")
{
   static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
        , STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
   hPipeRead:=""
   hPipeWrite:=""
   sOutput:=""
   DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
   DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
   
   VarSetCapacity(STARTUPINFO , siSize :=    A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
   NumPut(siSize              , STARTUPINFO)
   NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
   NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
   NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
   
   VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
   if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
                              , "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
   {
      DllCall("CloseHandle", "Ptr", hPipeRead)
      DllCall("CloseHandle", "Ptr", hPipeWrite)
      throw Exception("CreateProcess is failed")
   }
   DllCall("CloseHandle", "Ptr", hPipeWrite)
   VarSetCapacity(sTemp, 4096), nSize := 0
   while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
      sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
      ;sOutput .= stdOut := StrGet(&sTemp, nSize)
      ;sOutput .= stdOut := StrGet(&sTemp, nSize, CPX)
      ( callBackFuncObj && callBackFuncObj.Call(stdOut) )
   }
   DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
   DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
   DllCall("CloseHandle", "Ptr", hPipeRead)
   Return sOutput
}
;=========================================================================================

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 387 guests