Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enter something at a DOS prompt Programmatically?

Tags:

batch-file

I have program, that must interact with a console 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 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.

like image 994
Lonnie Best Avatar asked Mar 16 '10 19:03

Lonnie Best


People also ask

What is DOS command line?

The DOS command prompt is a critical part of the Microsoft Disk Operating System (MS-DOS) command line interface. It is the fundamental setting for the interface, where the prompt sets the stage for executing command lines of code.

How do I open a DOS screen?

Click on the Windows "Start" button. Select "Programs" Select "MS-DOS Prompt"


2 Answers

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.

like image 167
James Kolpack Avatar answered Sep 23 '22 21:09

James Kolpack


The post from Microsoft also clearly says :

Do not type a space between the "y" and the pipe symbol (|)

and indeed, I noticed that in my case

echo y | executable.exe

doesn't work while

echo y| executable.exe

works fine

like image 43
zigdapig Avatar answered Sep 23 '22 21:09

zigdapig