Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

batch file - How do you enter something at a DOS prompt Programmatically?

I have program, that must interact with a DOS program before my program can continue what it is doing. I'm trying to avoid my user from having to interact with this dos program. So, I created a .bat file that does everything I need to do except for the last step which still requires user interaction that I'm trying to avoid.

Specifically, the command I type ends up at a dos prompt where I need to automatically enter y and then enter (to say yes to the prompt) and then I want to exit out.

Is there any way that I can make this happen automatically without my user having to enter y and enter? Ideally, I'd like to have the console-window NOT even pop up while this is going on.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can pipe in a 'y' character into the program like so:

echo y | executable.exe

Multiple lines can be entered like so:

(echo y
echo n) | executable.exe

...which will pass first 'y' then 'n'.

See tip from Microsoft here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...