AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Making script read key words in dos prompt

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
StarThorn1



Joined: 12 Nov 2009
Posts: 5

PostPosted: Wed Nov 25, 2009 8:40 pm    Post subject: Making script read key words in dos prompt Reply with quote

How would I go about making my script do something if a dos prompt had a key word in?
Back to top
View user's profile Send private message
wooly_sammoth



Joined: 12 May 2009
Posts: 178
Location: Gloucester UK

PostPosted: Wed Nov 25, 2009 9:05 pm    Post subject: Reply with quote

Unfortunately text can't be extracted directly from the command prompt using ControlGetText or similar.

I have got around this in the past by instructing the Command Prompt to give it's output to a file. AutoHotKey can then parse this file to find the key word.


I'm sure there are other methods available but this is a nice simple way.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Nov 25, 2009 10:30 pm    Post subject: Reply with quote

how do I get the prompt to give me the text? I don't know how (yet) but I thought maybe I could tell autohotkey to highlight/mark all the text on the prompt, copy it, open a notepad, paste it.
Back to top
wooly_sammoth



Joined: 12 May 2009
Posts: 178
Location: Gloucester UK

PostPosted: Wed Nov 25, 2009 11:10 pm    Post subject: Reply with quote

As I said AHK can't copy text directly from the command prompt but you can get the prompt to output to a file.

An example of this would by to type the command
Code:
ping google.com > Desktop\google.txt
into the command prompt and press enter.

This will result in a text document on your desktop called google.txt which contains the results of the ping.

You can then use the AHK commands FileRead and Loop (parse a string) to get the text from that file and check it for any word you like
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1498
Location: switzerland

PostPosted: Thu Nov 26, 2009 10:01 pm    Post subject: Reply with quote

maybe don't understand what really wanted
an example sends to hidden DOS window , reads and show searched line
Code:
;-------- send to DOS and COPY DOS window --------------------------
;-------- from Laszlo ----------------------------------------------
DetectHiddenWindows On
Gui,2:Font,,FixedSys

DosCommand=ver
SearchedText=Microsoft

F1=%A_scriptdir%\test55.txt
ifexist,%F1%
  Filedelete,%F1%

Run %ComSpec% /k ,,hide,PID1                ;open a DOS window hidden

Gui,2:Add,Text,    x15   y40                   ,DOS command:
Gui,2:Add,Edit,    x140  y40   h20   w300 vVAR ,%DosCommand%
Gui,2:Add, Button, x0    y0    w0  h0  default gSTART1,

Gui,2:Add,Text,    x15   y80                    ,DOS WINDOW COPIED:
Gui,2:Add,Listbox, x10   y100  h390  w680 vLB3,

Gui,2:Show, x0 y0 h500  w700 ,SendToDOS
GuiControl,2:Focus,VAR
return
;-------------------------------------------------------

START1:
gui,2:submit,nohide
GuiControl,2:,LB3,|                                       ;clear listbox

   ControlSend, ,CLS,ahk_pid %PID1%, , ,                  ;send clear screen
   ControlSend, ,{enter},ahk_pid %PID1%, , ,              ;send enter
   ControlSend, ,%VAR%,ahk_pid %PID1%, , ,                ;send input value
   ControlSend, ,{enter},ahk_pid %PID1%, , ,              ;send enter
   sleep,1000

WinActivate ahk_pid %PID1%
sleep,1000
ClipBoard =
SendInput !{Space}es{Enter}          ; select/copy DOS english
;SendInput !{Space}ba{Enter}           ; select/copy DOS german
ClipWait 2
C2:=clipboard
Fileappend,%C2%,%F1%                                          ;can write to a file
;msgbox,262144,Push Escape to finish,%C2%
StringGetPos p, C2,`n, R1
P1:=(P+2)                                                      ;LAST line
StringMid,t,C2,P1,150
stringreplace,C2,C2,`r`n,|,all
GuiControl,2:,LB3,%C2%
GuiControl,2:,LB3,---------------------------------------------------
GuiControl,2:,LB3,Lastline=%t%

;---- show a searched line ---
loop,read,%F1%
  {
  LR=%A_loopreadline%
  ifinstring,LR,%SearchedText%
  SR=%LR%
  }
msgbox,Searched Text [%searchedtext%]=`n%SR%
return


2Guiclose:
process,close,%PID1%               ;close hidden DOS
exitapp
;--------------------------------------------------------
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group