如何测试STDIN是批量终端?

Zip*_*pon 4 stdin window batch-file

在shell中我可以这样做:

if test -t 0  ; then
  echo stdin is a tty
  exit 0
fi
Run Code Online (Sandbox Code Playgroud)

我怎么能批量做到这一点?

MC *_* ND 7

编辑 - 感谢所有测试人员.

@echo off
    timeout 1 2>nul >nul
    if errorlevel 1 (
        echo input redirected
    ) else (
        echo input is console
    )
Run Code Online (Sandbox Code Playgroud)

timeout命令尝试直接访问控制台,如果执行批处理文件,则会失败

myBatchFile.cmd < input.txt
echo something | myBatchFile.cmd
Run Code Online (Sandbox Code Playgroud)

在Windows XP上测试(从W2003 Resource Kit超时),7和8.1.