有没有办法检查外部数据是否通过管道传输到程序或程序是否独立运行?

rsk*_*k82 2 c++ windows console

即数据已由其他程序提供,或者用户必须手动输入.我指的是这两种状态:

dir /b /s *.* | myprogram
Run Code Online (Sandbox Code Playgroud)

和

myprogram
Run Code Online (Sandbox Code Playgroud)

在第二种情况下,程序将等待用户输入.有办法防止这种情况吗?

smo*_*ing 6

POSIX有isatty(),而Visual C++有_isatty(),如果文件描述符是终端或命令行,它们都将返回true,例如isatty(fileno(stdin)).