AutoHotkey Community

It is currently May 27th, 2012, 2:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: November 25th, 2009, 9:40 pm 
Offline

Joined: November 12th, 2009, 9:41 pm
Posts: 6
How would I go about making my script do something if a dos prompt had a key word in?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2009, 10:05 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2009, 11:30 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2009, 12:10 am 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2009, 11:01 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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
;--------------------------------------------------------


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn, XstatyK and 24 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group