【发布时间】:2016-08-20 02:52:57
【问题描述】:
This stackoverflow answer 包含以下代码:
dir /a-d "C:\PLUS\ADMIN\BATCH\*" >nul 2>nul && (
start "" cmd /c "@echo Files in the directory! &@echo(&@pause
) || (
echo there are no files
)
>nul 是将stdout 重定向到nul。 2>nul 的用途是什么,在什么情况下需要它?
【问题讨论】:
-
这不是被问到的,所以我在这里发表评论。 Start "" 打开第二个控制台窗口,运行 cmd /c 启动一个新的命令interperter。在 ...@pause 之后可能有一个结束引号 ",但它不是必需的。如果运行 Windows,请打开控制台窗口并输入 help start 以获取有关启动的更多信息,并帮助 cmd 获取有关 cmd 的信息。
-
@RockPaperLizard 请参阅 Microsoft 关于 Using command redirection operators 的文章。
-
@Mofi 非常感谢。很棒的文章。顺便说一句,那篇文章列在 Windows XP 的命令行参考 下。 MS 是否有类似的 Windows 7 命令行参考?
-
@RockPaperLizard 是的,Windows Server 2003、Windows Vista、Windows XP、Windows Server 2008、Windows 7、Windows Server 2003 R2、Windows Server 2008 R2、Windows Server 2000 有一个更新的Command-Line Reference , Windows Server 2012, Windows 8。但它不包含有关命令重定向运算符的文章。
-
@RockPaperLizard 您可能还对来自 SS64 An A-Z Index of the Windows CMD command line 的 SS64 文章 Command redirections, Pipes 感兴趣。由于考虑了所有 Windows 版本,所以关于 SS64 的文档通常更好。
标签: windows batch-file command-line output stdout