DOS / XP bat file programming question

B

+Bob+

It's been a long time since I've done this and my memory grows foggy

How do I feed a "y" response to a DOS command that wants to prompt me
for a Y/N answer?

How about if it prompts for two in a row?

Thanks,
 
G

Guest

echo y|command.exe

The pipe command (shifted \ on UK keyboards) redirects output to another
program's standard input.

To handle the two-in-a-row situation, create a textfile containing the two
commands on separate lines. Now do

command.exe <file.txt

The first almost always works, the second may or may not work depending on
how the executable takes its input.
 
P

Pegasus \(MVP\)

+Bob+ said:
It's been a long time since I've done this and my memory grows foggy

How do I feed a "y" response to a DOS command that wants to prompt me
for a Y/N answer?

How about if it prompts for two in a row?

Thanks,

As Ian suggested, piping Y into a command will do the trick,
e.g. like so:

echo F | xcopy c:\*.* d:\Test

Note that DOS is an operating system, same as Windows XP.
There is no DOS under Windows, only a Command Prompt.
 
P

Pegasus \(MVP\)

Ian said:
echo y|command.exe

The pipe command (shifted \ on UK keyboards) redirects output to another
program's standard input.

To handle the two-in-a-row situation, create a textfile containing the two
commands on separate lines. Now do

command.exe <file.txt

The first almost always works, the second may or may not work depending on
how the executable takes its input.

Your reply is basically correct but contains a couple of
oversights:
- There is no point in piping Y into a command processor.
The command processor will ignore it.
- The standard command processor for WinXP is cmd.exe.
Command.com is a legacy 16-bit processor that should not
be used.
 
B

+Bob+

To handle the two-in-a-row situation, create a textfile containing the two
commands on separate lines. Now do

command.exe <file.txt

The first almost always works, the second may or may not work depending on
how the executable takes its input.

I'm not sure that I was clear about the second version. In that, I
need two "y"'s fed to the same (just one command). That is, the
command asks for a confirmation, then a moment later the same command
asks for another confirmation.

Can you give me an example of what the file.txt would look like for a
psuedo-command named "doIt" ?

Pre example - at the command line, I'd do this

c:> doit param1

Are you sure you want to do it?: Y

Operation compete, proceed with irreversible phase II: Y

C:>

- end example


Thanks!
 
P

Pegasus \(MVP\)

+Bob+ said:
I'm not sure that I was clear about the second version. In that, I
need two "y"'s fed to the same (just one command). That is, the
command asks for a confirmation, then a moment later the same command
asks for another confirmation.

Can you give me an example of what the file.txt would look like for a
psuedo-command named "doIt" ?

Pre example - at the command line, I'd do this

c:> doit param1

Are you sure you want to do it?: Y

Operation compete, proceed with irreversible phase II: Y

C:>

- end example


Thanks!

As Ian suggested, some applications will respond to a string
piped into the command at launch time. However, it is not
possible to pipe two responses into an application, because
the application will empty its input buffer when the response
to the first prompt is processed.
 
P

Paul Randall

Pegasus (MVP) said:
As Ian suggested, piping Y into a command will do the trick,
e.g. like so:

echo F | xcopy c:\*.* d:\Test

Note that DOS is an operating system, same as Windows XP.
There is no DOS under Windows, only a Command Prompt.

In Help 7 Support, search for Command-line reference A-Z, to learn all about
"changes to the functionality of MS-DOS commands, new command-line tools,
command shell functionality, configuring the command prompt, and automating
commmand-line tasks". It may not be DOS, but Microsoft still refers to the
commands as MS-DOS commands, so it is not totally unreasonable to refer to
the window in which one uses the MS-DOS commands as a DOS window.

The Cmd.exe window, displays something like this when you open it:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

The Command.com window displays something like this when you open it:
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.
I kinda think that this really is running a version of DOS under Windows,
but I could be wrong.

Both windows can run batch files, but the CMD window is much more versatile.
It has many more commands and more powerful batch capabilities than the
Command.com window.

WXP can format a disk creating an MS-DOS startup disk. I believe on bootup
it would actually be DOS and have capabilities similar to the Command.com
window.

-Paul Randall
 
P

Pegasus \(MVP\)

Paul Randall said:
Pegasus (MVP) said:
As Ian suggested, piping Y into a command will do the trick,
e.g. like so:

echo F | xcopy c:\*.* d:\Test

Note that DOS is an operating system, same as Windows XP.
There is no DOS under Windows, only a Command Prompt.

In Help 7 Support, search for Command-line reference A-Z, to learn all
about "changes to the functionality of MS-DOS commands, new command-line
tools, command shell functionality, configuring the command prompt, and
automating commmand-line tasks". It may not be DOS, but Microsoft still
refers to the commands as MS-DOS commands, so it is not totally
unreasonable to refer to the window in which one uses the MS-DOS commands
as a DOS window.

The Cmd.exe window, displays something like this when you open it:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

The Command.com window displays something like this when you open it:
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.
I kinda think that this really is running a version of DOS under Windows,
but I could be wrong.

Both windows can run batch files, but the CMD window is much more
versatile. It has many more commands and more powerful batch capabilities
than the Command.com window.

WXP can format a disk creating an MS-DOS startup disk. I believe on
bootup it would actually be DOS and have capabilities similar to the
Command.com window.

-Paul Randall

I'm quite aware of Microsoft programmers sometimes getting
confused themselves about their own operating system. It's kind
of hard to understand . . . Nevertheless, the distinction must be
made because without it people get confused. On countless
occasions have I seen posts in this group that referred to fdisk.exe
or to sys.com, both of which are fundamental components of DOS
but have no place in Windows. Some posters complain about
format.com not working under "DOS", meaning that format.com
may not work in the Command Prompt under WinXP. Some
ask how to boot their WinXP machine into DOS, which they
obviously can't because WinXP (as opposed to Win9x) is not
built on DOS.

Perhaps Microsoft has finally purged all references to DOS
from Vista.

About the command processor: Why would Ian suggest to
the OP to use a legacy Win9x processor when, as you say,
the real thing is so much more powerful and has full 32-bit
capability?

While WinXP may be able to format a DOS boot diskette,
the capabilities of this boot disk would be extremely limited
to the point of being almost useless. If you need a good boot
disk then you should look at a Bart PE boot CD or one of
its derivatives.
 
K

Ken Blake, MVP

Your reply is basically correct but contains a couple of
oversights:
- There is no point in piping Y into a command processor.
The command processor will ignore it.
- The standard command processor for WinXP is cmd.exe.
Command.com is a legacy 16-bit processor that should not
be used.


My interpretation of his message was not that he meant command.exe to
be a command processor, but that he was using the word "command" as a
generic command, to represent whatever command the Y should be piped
to.

Perhaps it would have been clearer if he had written something like

echo y | anycommand.exe
 
C

cquirke (MVP Windows shell/user)

On Mon, 23 Jul 2007 06:00:02 -0700, Ian
echo y|command.exe
The pipe command (shifted \ on UK keyboards) redirects output to another
program's standard input.
To handle the two-in-a-row situation, create a textfile containing the two
commands on separate lines. Now do
command.exe <file.txt
The first almost always works, the second may or may not work depending on
how the executable takes its input.

You may have to be careful with "Enter" characters, i.e. you may have
to hack the .TXT to use "naked" CHAR(13) rather than CHAR(10):CHAR(13)
combinations. I remember that issue from automating FDisk to swap
active partitions way back in the MS-DOS vs. PICK days.

To do this, I'd write the file with ! instead of Enter, e.g. not...

y
y

....but...

y!y!

....and then use a hex editor to "poke' the two ! (33h) chars to
CHAR(13), which is 0Dh

A third (and best, where possible) approach is to see whether the
command you are automating, has syntax to bypass the prompts.
Entering the command name followed by /? will usually show the
relevant syntax help. This is possible for many file-orientated
commands such as Del, DelTree, Copy, XCopy, RM, etc.

BTW: Some commands automatically default differently when used in
batch files, e.g. Copy prompts to overwrite when used interactively,
but overwrites without prompting when used in a batch file.

Consider also the impact of failure, when coding batch files, e.g...

C:
CD \Missing\Path
Del *.*

....compared to...

Del C:\Missing\Path*.*

....and remember that "Exist ..NUL" writes to the target.


--------------- ----- ---- --- -- - - -
To one who only has a hammer,
everything looks like a nail
 
C

cquirke (MVP Windows shell/user)

Your reply contains a couple of oversights:
- There is no point in piping Y into a command processor.
The command processor will ignore it.
- The standard command processor for WinXP is cmd.exe.
Command.com is a legacy 16-bit processor that should not
be used.

I blinked on that at first ("it's Command.com not Command.exe") until
I guessed "Command.exe" was just an example placeholder ;-)


--------------- ----- ---- --- -- - - -
To one who has never seen a hammer,
nothing looks like a nail
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top