Batch file 如何测试STDIN是否为批量终端?
在shell中,我可以这样做:Batch file 如何测试STDIN是否为批量终端?,batch-file,window,stdin,Batch File,Window,Stdin,在shell中,我可以这样做: if test -t 0 ; then echo stdin is a tty exit 0 fi 我怎样才能批量完成这项工作?已编辑-感谢所有测试人员 @echo off timeout 1 2>nul >nul if errorlevel 1 ( echo input redirected ) else ( echo input is console ) timeout命
if test -t 0 ; then
echo stdin is a tty
exit 0
fi
我怎样才能批量完成这项工作?已编辑-感谢所有测试人员
@echo off
timeout 1 2>nul >nul
if errorlevel 1 (
echo input redirected
) else (
echo input is console
)
timeout命令尝试直接访问控制台,如果批处理文件按如下方式执行,则此操作将失败
myBatchFile.cmd < input.txt
echo something | myBatchFile.cmd
myBatchFile.cmd
在Windows XP(W2003资源工具包中的超时)、7和8.1上测试。+1它在这里工作!在Windows 8.1中测试(我喜欢这个…
timeout 0 2>nul>nul
似乎也能工作,并避免1秒延迟。@rivy,仅仅是从内存中(4年后),也许我错了,我相信1
的原因是timeout
可执行文件的某个版本不允许0
作为有效值。但现在我只限于W1064B,至少在这个版本中你是对的。非常感谢。