公告
财富商城
积分规则
提问
发文
2019-02-18 03:38发布
来,给爷笑一个
In shell I can do this:
if test -t 0 ; then echo stdin is a tty exit 0 fi
How can I do this in batch?
EDITED - Thank you to all the testers.
@echo off timeout 1 2>nul >nul if errorlevel 1 ( echo input redirected ) else ( echo input is console )
The timeout command tries to directly get access to the console, and this will fail if the batch file is executed as
myBatchFile.cmd < input.txt echo something | myBatchFile.cmd
Tested on Windows XP (timeout from W2003 Resource Kit), 7 and 8.1.
最多设置5个标签!
EDITED - Thank you to all the testers.
The timeout command tries to directly get access to the console, and this will fail if the batch file is executed as
Tested on Windows XP (timeout from W2003 Resource Kit), 7 and 8.1.