Sign in to follow this  
Followers 0
siage

how to keep the cmd window active

7 posts in this topic

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 ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@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

Share this post


Link to post
Share on other sites

@siage

try doing it with just the cmd line:

Run(@ComSpec & " /c echo y | chkdsk /r e:")

(not tested on chkdsk, but works fine on a format command for me)

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0