问题
I am writing a simple batch file (remove.bat) to remove a directory and all its subdirectories. The file contains the following command-
rmdir /S modules
where modules is the name of the non-empty directory.
I get the following message -
C:\...\bin>rmdir /S modules
modules, Are you sure (Y/N)?
How can I supply through the batch file the console input "Y" to the Y/N question above? Is there a command that can do this?
回答1:
As others have pointed out, you should use the /Q
option. But there is another "old school" way to do it that was used back in the day when commands did not have options to suppress confirmation messages. Simply ECHO the needed response and pipe the value into the command.
echo y|rmdir /s modules
I recommend using the /Q
option instead, but the pipe technique might be important if you ever run into a command that does not provide an option to suppress confirmation messages.
回答2:
Do rmdir /S
for deleting a non-empty directory and do rmdir /Q
for not prompting. Combine to rmdir /S /Q
for quietly delete non-empty directories.
回答3:
You can do
rmdir /Q
Q is for quiet
回答4:
Use rmdir /S /Q modules
/Q
suppresses the confirmation prompt.
回答5:
I just want to add that, although not applicable to Rmdir, a force switch may also be the solution in some cases. So in a general sense you should look at your command switches for /f, /q, or some variant thereof (for example, Netdom RenameComputer uses /Force, not /f).
The echo pipe is a neat trick and very useful to keep around since you wont always find an appropriate switch. For instance, I think it's the only way to bypass this Y/N prompt...
Echo y|NETDOM COMPUTERNAME WorkComp /Add:Work-Comp
Link to nearly identical StackOverflow post
来源:https://stackoverflow.com/questions/15147900/how-to-supply-console-input-yes-no-as-part-of-batch-file-on-windows