How to supply console input ( yes / no ) as part of batch file on Windows.

后端 未结 6 885
春和景丽
春和景丽 2020-12-08 08:33

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
         


        
6条回答
  •  轮回少年
    2020-12-08 09:18

    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

提交回复
热议问题