[英]is there a way to check if external data is piped to a program or if program runs on its own?
That is the data is already provided by another program, or user must type it manually. 即数据已由其他程序提供,或者用户必须手动输入。 I mean these two states:
我指的是这两种状态:
dir /b /s *.* | myprogram
and 和
myprogram
In second case the program would be waiting for user input. 在第二种情况下,程序将等待用户输入。 Is there a way to prevent that ?
有办法防止这种情况吗?
POSIX具有isatty()
,而Visual C ++具有_isatty()
,如果文件描述符是终端或命令行,则两者都将返回true,例如isatty(fileno(stdin))
。
Yes. 是。 Use
GetStdHandle
to get the STD_INPUT_HANDLE
and then check that the handle is of the type FILE_TYPE_PIPE
in the first case or FILE_TYPE_CHAR
in the second case by calling GetFileType
on it. 使用
GetStdHandle
得到STD_INPUT_HANDLE
,然后检查手柄类型的FILE_TYPE_PIPE
在第一种情况下或FILE_TYPE_CHAR
在第二种情况下,通过调用GetFileType
就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.