简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM