Batch file command

What is the syntax for an automatic yes in a batch file.

Forinstance.bat
format a:

produces a “‘y’ or ‘n’” dialogue.
But there is a way around it.
Can’t remember and can’t find it.

Something like:

Almostright.bat
format a: << “y”

try format a: < y

That should be echo y ¦ format a: . Format a: < y would take the input to format from a file called y, if any such file existed.

Usually, such switches are given follwing a forward slash, or a dash, but there’s no point in using a switch that isn’t one of the range specifically designed to work with the command in question, for example (in the command line of Windows XP), there isn’t any switch for the format command that would override the screen prompts. These are the available switches and command syntax options:


FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X]
FORMAT volume [/V:label] [/Q] [/F:size]
FORMAT volume [/V:label] [/Q] [/T:tracks /N:sectors]
FORMAT volume [/V:label] [/Q]
FORMAT volume [/Q]

  volume          Specifies the drive letter (followed by a colon),
                  mount point, or volume name.
  /FS:filesystem  Specifies the type of the file system (FAT, FAT32, or NTFS).
  /V:label        Specifies the volume label.
  /Q              Performs a quick format.
  /C              NTFS only: Files created on the new volume will be compressed
                  by default.
  /X              Forces the volume to dismount first if necessary.  All opened
                  handles to the volume would no longer be valid.
  /A:size         Overrides the default allocation unit size. Default settings
                  are strongly recommended for general use.
                  NTFS supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K.
                  FAT supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
                  (128K, 256K for sector size > 512 bytes).
                  FAT32 supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
                  (128K, 256K for sector size > 512 bytes).

                  Note that the FAT and FAT32 files systems impose the
                  following restrictions on the number of clusters on a volume:

                  FAT: Number of clusters <= 65526
                  FAT32: 65526 < Number of clusters < 4177918

                  Format will immediately stop processing if it decides that
                  the above requirements cannot be met using the specified
                  cluster size.

                  NTFS compression is not supported for allocation unit sizes
                  above 4096.

  /F:size         Specifies the size of the floppy disk to format (1.44)
  /T:tracks       Specifies the number of tracks per disk side.
  /N:sectors      Specifies the number of sectors per track.

Usram is correct, you could use the echo command in commands that don’t have an override command line switch, or you can use the redirector (the <) along with a text file that has the response you want.

For example, to use the redirection approach, create a simple text file with nothing but the letter Y and a carriage return. Call it “y.txt”.

Then you can type (or put in a batch file)
format a: < y.txt

and away it goes.

Heres the deal: I’ve got an old Pentium laptop running Win98. Since hard disk space is at a premium I have a batch file to delete c:\windows emp which is not deleted by cleandisk.exe.

echo y | del c:\windows emp*.*
Works.

echo y | deltree c:\windows emp*.*
Doesn’t work. In fact it hangs the msdos window.
And it creates it own directory in …/temp with a file with only an ‘y’.

Riddle me that, Batman!

It’s easier than that. DELTREE takes a /y switch to run without confirmation.

DELTREE /Y c:\windows emp*.*