[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5447
  • Last Modified:

simulating a key press in a ms-dos batch file

i need to simulate a key press in an ms-dos batch file

it reads:

press any key to continue

and i need to batch file to do that for me
0
johnlwarence
Asked:
johnlwarence
  • 3
  • 2
  • 2
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
This depends on what's asking for the key to be pressed.  You can try two things:

Echo y| ProgramNameThatAsksForYouToPressAnyKey

And:
create a text file, with a key (y - as in yes, h as in "any key", etc) and be sure you hit enter in the text file.  Then save it, for example, as y.txt

Then use input redirection:

ProgramNameThatAsksForYouToPressAnyKey < y.txt
0
 
brianadkinsCommented:

Why not just edit the batch file and comment out the 'pause' command?

::pause

or

rem pause
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
That assumes there's a pause in the batch file.  
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
brianadkinsCommented:

True, but I think it's not a stretch to assume that if a batch file produces the output "press any key to continue", and requires a keystroke to continue, that a 'pause' command is behind it...

But you are correct, there could be a different, third-party program called by the batch file to produce that scenario.
0
 
WatzmanCommented:

Try input redirection.

Create a text file with the keyboard responses in it, in this case a "Y" on a line by itself.  Call it "yes.txt"

Then

C:\>runthis.bat<yes.txt

The batch file gets it's input from the text file instead of the keyboard.  This doesn't always work, and even when it does may take some experimentation and playing around with to get right.  Also, if there are other responses, they will have to be there also.



0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Um, excuse me... Did you read my first comment?

That's what I said to do.
0
 
WatzmanCommented:
Hey, lee ... I didn't read your post that closely, but you are right.  I agree that you should get the points.  Unfortunately, I'm not the author.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now