Jump to content

how to keep the cmd window active


 Share

Recommended Posts

Hello all, I'm the new comer to AutoIt, I write my first AutoIt script to perform check disk task in winpe environment,when the script executed, a window popup and then waiting the user's confirm, I use send("{Y 1}{enter 1}") to input Y and enter, but it seemed not work.I think the popuped windows not active. I use the LANDesk provisioning to execute AutoIt script,it execute startnet.cmd first, then call AutoIt script.

My script

run("chkdsk /r e:")

sleep(2000)

send("{Y 1}{enter 1}")

sleep(2000)

send("{Y 1}{enter 1}")

sleep(2000)

send("{Y 1}{enter 1}")

Who can help me to resolve it ?

Link to comment
Share on other sites

What do you want to achieve with

send("{Y 1}{enter 1}")

Send Key "Y" followed by "Enter"? In this case you should code:

Send("Y{ENTER}")
Edited by water

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

What do you want to achieve with

send("{Y 1}{enter 1}")

Send Key "Y" followed by "Enter"? In this case you should code:

Send("Y{ENTER}")

I thought {Y 1} input Y only once, I followed your instruction, it worked well.I'll fix it. but how can I make sure the "Y" send to the correct cmd window?I mean the window with chkdsk command?
Link to comment
Share on other sites

@siage

*edit: oops, misunderstood what was going on.. chkdsk is prompting for input with another window? Have you tried using the AutoIT Window Info tool to see what the window's title, classname, etc are? You should be able to get a handle to that, and send a command to it based on what you want to do. If there are buttons, you could just send a 'space' to the 'Yes' button etc

Edited by Ascend4nt
Link to comment
Share on other sites

@siage,

Welcome to the forum :-)

I thought {Y 1} input Y only once, ...

The syntax that you used is correct, but not needed. The brackets are optional except when sending a key like ENTER, ESC, PAUSE...

The number of times to send it is also optional if it is 1 time.

So:

Send("Y")

Send("{Y}")

Send("{Y 1}")

are the same.

And:

Send("YY")

Send("{Y}{Y}")

Send("{Y 2}")

are the same.

Anyway, whim gave you a good solution.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Siage welcome to AutoIt check the help file and search for StdinWrite

This code is from the StdinWrite() help file example slightly modify to your need:

#include <Constants.au3>

Local $PID = Run("chkdsk /r e:", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
; Write string to STDIN
StdinWrite($PID, 'Y' & @CRLF)
; Calling with no 2nd arg closes stream
StdinWrite($PID)

; Read from child's STDOUT and show
Local $data
While True
    $data &= StdoutRead($PID)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)
Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
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...