如何在 Windows 上将控制台输入(是/否)作为批处理文件的一部分提供. [英] How to supply console input ( yes / no ) as part of batch file on Windows.

查看:16
本文介绍了如何在 Windows 上将控制台输入(是/否)作为批处理文件的一部分提供.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的批处理文件 (remove.bat) 来删除一个目录及其所有子目录.该文件包含以下命令 -

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

其中 modules 是非空目录的名称.

where modules is the name of the non-empty directory.

我收到以下消息 -

C:...in>rmdir /S modules
modules, Are you sure (Y/N)?

如何通过批处理文件向上面的 Y/N 问题提供控制台输入Y"?有没有可以做到这一点的命令?

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?

推荐答案

正如其他人指出的那样,您应该使用 /Q 选项.但还有另一个老派".在命令没有选项来抑制确认消息的时候使用的方法.只需 ECHO 所需的响应并将值通过管道传输到命令中.

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

我建议改用 /Q 选项,但如果您遇到不提供抑制确认消息选项的命令,管道技术可能很重要.

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.

注意 - 这种技术只有在命令从标准输入读取输入时才有效,cmd.exe 内部命令总是如此.但这对于某些外部命令可能不是真的.

这篇关于如何在 Windows 上将控制台输入(是/否)作为批处理文件的一部分提供.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆