gpt4 book ai didi

batch-file - 如何批量测试STDIN是否为终端?

转载 作者:行者123 更新时间:2023-12-04 23:50:50 25 4
gpt4 key购买 nike

在 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 命令试图直接访问控制台,如果批处理文件被执行,这将失败
myBatchFile.cmd < input.txt
echo something | myBatchFile.cmd

在 Windows XP(W2003 Resource Kit 超时)、7 和 8.1 上测试。

关于batch-file - 如何批量测试STDIN是否为终端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22726198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com