Jump to content

DOS / XP bat file programming question


Recommended Posts

Guest +Bob+
Posted

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,

  • Replies 10
  • Created
  • Last Reply
Posted

RE: DOS / XP bat file programming question

 

 

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.

Guest Pegasus \(MVP\)
Posted

Re: DOS / XP bat file programming question

 

 

"+Bob+" <uctraing@ultranet.com> wrote in message

news:7k89a35jgedhhc6dgm2khrauvh1c95r0ha@4ax.com...

> 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.

Guest Pegasus \(MVP\)
Posted

Re: DOS / XP bat file programming question

 

 

"Ian" <Ian@discussions.microsoft.com> wrote in message

news:5D8D6790-5E5B-4954-9602-11F387C596BD@microsoft.com...

>

> 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.

Guest +Bob+
Posted

Re: DOS / XP bat file programming question

 

On Mon, 23 Jul 2007 06:00:02 -0700, Ian

<Ian@discussions.microsoft.com> wrote:

>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!

Guest Pegasus \(MVP\)
Posted

Re: DOS / XP bat file programming question

 

 

"+Bob+" <uctraing@ultranet.com> wrote in message

news:1nd9a3d3po91lr1tgnpvjlupga0bp4iebb@4ax.com...

> On Mon, 23 Jul 2007 06:00:02 -0700, Ian

> <Ian@discussions.microsoft.com> wrote:

>

>>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!

 

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.

Guest Paul Randall
Posted

Re: DOS / XP bat file programming question

 

 

"Pegasus (MVP)" <I.can@fly.com> wrote in message

news:uEZJTtSzHHA.1188@TK2MSFTNGP04.phx.gbl...

>

> "+Bob+" <uctraing@ultranet.com> wrote in message

> news:7k89a35jgedhhc6dgm2khrauvh1c95r0ha@4ax.com...

>> 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.

 

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]

© Copyright 1985-2001 Microsoft Corp.

 

The Command.com window displays something like this when you open it:

Microsoft® Windows DOS

©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

Guest Pegasus \(MVP\)
Posted

Re: DOS / XP bat file programming question

 

 

"Paul Randall" <paulr901@cableone.net> wrote in message

news:eHEtz%23TzHHA.1208@TK2MSFTNGP03.phx.gbl...

>

> "Pegasus (MVP)" <I.can@fly.com> wrote in message

> news:uEZJTtSzHHA.1188@TK2MSFTNGP04.phx.gbl...

>>

>> "+Bob+" <uctraing@ultranet.com> wrote in message

>> news:7k89a35jgedhhc6dgm2khrauvh1c95r0ha@4ax.com...

>>> 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.

>

> 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]

> © Copyright 1985-2001 Microsoft Corp.

>

> The Command.com window displays something like this when you open it:

> Microsoft® Windows DOS

> ©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.

Guest Ken Blake, MVP
Posted

Re: DOS / XP bat file programming question

 

On Mon, 23 Jul 2007 15:16:04 +0200, "Pegasus \(MVP\)" <I.can@fly.com>

wrote:

>

> "Ian" <Ian@discussions.microsoft.com> wrote in message

> news:5D8D6790-5E5B-4954-9602-11F387C596BD@microsoft.com...

> >

> > 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.

 

 

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

 

--

Ken Blake, Microsoft MVP Windows - Shell/User

Please Reply to the Newsgroup

Guest cquirke (MVP Windows shell/user)
Posted

Re: DOS / XP bat file programming question

 

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

>--------------- ----- ---- --- -- - - -

Guest cquirke (MVP Windows shell/user)
Posted

Re: DOS / XP bat file programming question

 

On Mon, 23 Jul 2007 15:16:04 +0200, "Pegasus \(MVP\)" wrote:

>"Ian" <Ian@discussions.microsoft.com> wrote in message

>> echo y|command.exe

>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

>--------------- ----- ---- --- -- - - -


×
×
  • Create New...