sqa Posted September 16, 2013 Share Posted September 16, 2013 Hi, I am writing a script that writes commands to Command Prompt and have to set Sleep() to something approximate to let it to be executed for sure. Is there a possibility to wait until the certain line was printed out in Command Prompt, like when my command was executed Command Prompt returns to (let say) C:>? Thanks Link to comment Share on other sites More sharing options...
water Posted September 16, 2013 Share Posted September 16, 2013 Can you please post some example code? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
sqa Posted September 16, 2013 Author Share Posted September 16, 2013 for example: Run("cmd.exe") 1. WinWaitActive("Administrator: C:\Windows\System32\cmd.exe", "", 15) 2. Send('cd C:/' & "{ENTER}") 3. Sleep(300) 4. send('mvn clean install > ' & $logFile & "{ENTER}") 5. Sleep(10000) so, sleep(10000) is a kind of long time to wait but I cannot reduce it in case if something happens and will take longer. That's why I am wondering if there is a possibility to wait for a specific line in Com. Prompt to be sure that the last command (let say #4) was executed. Link to comment Share on other sites More sharing options...
tester123 Posted September 16, 2013 Share Posted September 16, 2013 1. WinWaitActive("Administrator: C:\Windows\System32\cmd.exe", "", 15) 2. Send('cd C:/' & "{ENTER}") 3. Sleep(300) 4. send('mvn clean install > ' & $logFile & "{ENTER}") 5. Sleep(100) 6.Do 7.Sleep (100) 8.Until 9.<<Add something unique to your process>> Could be ControlCommand + isVisible/isEnabled Link to comment Share on other sites More sharing options...
water Posted September 17, 2013 Share Posted September 17, 2013 You can concatenate DOS commands using "&&" in a single string and then pass this string to Run: $CMD = "command1 && command2" Run(@ComSpec & " /c " & $CMD, "", @SW_HIDE) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
sqa Posted September 17, 2013 Author Share Posted September 17, 2013 OK, but is there a possibility to wait for a certain line in DOS like let say: WinWait("Administrator: Command Prompt", "C:Users")? Link to comment Share on other sites More sharing options...
water Posted September 17, 2013 Share Posted September 17, 2013 Why do you want to wait or such a line? All commands passed to Run are processed in sequence. If you replace Run with RunWait AutoIt gets control again after all commands have been processed. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
sqa Posted September 17, 2013 Author Share Posted September 17, 2013 Oh, now I see what you mean, Thanks Link to comment Share on other sites More sharing options...
water Posted September 17, 2013 Share Posted September 17, 2013 Glad to be of service My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Gianni Posted September 17, 2013 Share Posted September 17, 2013 (edited) OK, but is there a possibility to wait for a certain line in DOS like let say: WinWait("Administrator: Command Prompt", "C:Users")? Hi sqa If you want to wait for a certain line in DOS output, You could use DOS I/O redirection to execute dos commands and read directly the output stream so you could check if the output contains the string you are waiting for. The check string could be a "well known string" or you could concatenate an echo command with your "termination" string. In this way, while the dos command is running, your script can do other activities, and you only sometime can check the output of dos command to see if your string is in the output For example: expandcollapse popup#include <Constants.au3> Local $Output ; here we start a hidden DOS prompt to be used when needed (it remains alive becouse of /K parameter) Global $prompt = Run(@ComSpec & " /K", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD + $STDERR_MERGED) Do ; wait untill prompt is ready Sleep(100) Until StringInStr(StdoutRead($prompt), ">") ; . . . do what you want with your script . . . . ; when you want run one or more dos command, simply use StdinWrite in this way: ; example of more commands in one line (set drive c: ; set root directory ; echo hello StdinWrite($prompt, "c:" & @CRLF & "cd C:\" & @CRLF & "echo hello" & @CRLF) Do ; . . . do other things with your script . . . . ; sometime check the output by reading the output stream of previously sent DOS commands. ; here we check if the "hello" character has been "displayed" If StringInStr(StdoutRead($prompt), "hello") Then MsgBox(0, "", 'DETECTED "hello" in dos output', 5) ExitLoop EndIf Until 1 > 1 ; now a little longer time consuming command ; execute ping command and then execute an echo command StdinWrite($prompt, "ping 127.0.0.1 -n 20" & @CRLF & "echo IHaveFinished" & @CRLF) $Timer = TimerInit() Do If TimerDiff($Timer) > 2000 Then ; every 2 seconds shows time just to show another activity ConsoleWrite("now It's " & @HOUR & ":" & @MIN & ":" & @SEC & " and dos command is still running..." & "(end string not detected)" & @CRLF) $Timer = TimerInit() EndIf $Output = StdoutRead($prompt) If StringInStr($Output, "IHaveFinished") Then ConsoleWrite("Finished" & @CRLF) MsgBox(0, "", 'DETECTED "IHaveFinished" in dos output', 5) ExitLoop EndIf Until 1 > 1 ProcessClose($prompt) bye Edited September 17, 2013 by PincoPanco guiltyking 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now