Jump to content

Command Prompt outputs


sqa
 Share

Recommended Posts

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

Can you please post some example code?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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

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

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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 2022-02-19 - Version 1.6.1.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 (NEW 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

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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:

#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 by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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...