wordpress
发布时间:2022-04-02 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了batch-file – 如何测试STDIN是批量终端?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
在 s
Hell中我可以这样做: 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 (
@H_
675_13@
在
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命令尝试直接访问控制台,如果执行批处理文件,则会失败
@H_113_21@myBatchFile.cmd < input.txt
echo something | myBatchFile.cmd
在Windows XP上测试(从W2003 resource Kit超时),7和8.1.