有没有办法检查外部数据是否被管道传输到程序或者程序是否自己运行? [英] is there a way to check if external data is piped to a program or if program runs on its own?

查看:203
本文介绍了有没有办法检查外部数据是否被管道传输到程序或者程序是否自己运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是数据已经由另一个程序提供,或者用户必须手动键入。
我的意思是这两种状态:

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

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))

POSIX has isatty(), whereas Visual C++ has _isatty(), both of which will return true if a file descriptor is a terminal or command line, e.g. isatty(fileno(stdin)).

这篇关于有没有办法检查外部数据是否被管道传输到程序或者程序是否自己运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆