检查进程是否有stdin句柄 [英] Check if process has a stdin handle

查看:86
本文介绍了检查进程是否有stdin句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


有没有办法检查当前进程是否有stdin句柄?在

win32 API中,可以做到:


_eof(_fileno(stdin))


至关重要是上面没有阻止。是否有一种标准的方式

来做同样的操作而不诉诸OS特定的API调用?

Hello.

Is there a way to check if the current process has an stdin handle? In
the win32 API, one can do:

_eof(_fileno(stdin))

Crucial here is that the above doesn''t block. Is there a standard way
to do the same without resorting to OS-specific API calls?

推荐答案

Nikos Chantziaras写道在08/01/07 09:50,:
Nikos Chantziaras wrote On 08/01/07 09:50,:

你好。


有没有办法检查当前进程有一个stdin句柄?在

win32 API中,可以做到:


_eof(_fileno(stdin))


至关重要是上面没有阻止。有没有标准的方式

来做同样的事情而不诉诸OS特定的API调用?
Hello.

Is there a way to check if the current process has an stdin handle? In
the win32 API, one can do:

_eof(_fileno(stdin))

Crucial here is that the above doesn''t block. Is there a standard way
to do the same without resorting to OS-specific API calls?



什么是stdin句柄,什么意思

进程拥有一个?


在托管环境中,目前main()是

首先调用三个流stdin,stdout,stderr

是开放的,随时准备采取行动。它们将保持如此状态,直到程序结束,或者你关闭它们,或者发生I / O

错误。可以使用

ferror()函数检测I / O错误。如果你关闭这些流中的任何一个

,你应该知道你已经完成了它。将代码写入

确定包含

的程序之后的流的状态代码退出是留给读者的练习;-)

-
Er ********* @ sun.com


文章< 1185978665.736059@news1nwk>,

Eric Sosman< Er ********* @ Sun .COMWrote:
In article <1185978665.736059@news1nwk>,
Eric Sosman <Er*********@Sun.COMwrote:

在托管环境中,目前main()首先被称为三个流stdin,stdout,stderr
打开并准备采取行动。
In a hosted environment, at the moment main() is
first called the three streams stdin, stdout, stderr
are open and ready for action.



理论上可能,但有没有任何操作系统确实可以保证

Theoretically perhaps, but are there any operating systems where that
is in fact guaranteed?


>这里的关键是上面没有阻止。有没有一种标准的方法可以在不诉诸特定于操作系统的API调用的情况下做同样的事情?
>Crucial here is that the above doesn''t block. Is there a standard way
to do the same without resorting to OS-specific API calls?



我不这么认为。在unix上,一个自然的事情就是调用fstat()和

看看你是否得到了EBADF。但是为了不做它会更便携

它:使用一些其他标准来决定是否使用stdin。这是典型的unix方法的b / b:cat只有当它没有任何文件名参数时才会读取stdin;它并不试图确定阅读是否会阻止

stdin。


- Richard

-

考虑在一些字母表中需要多达32个字符

- X3.4,1963。

I don''t think so. On unix, a natural thing would be call fstat() and
see if you get EBADF. But it would be more portable just to not do
it: use some other criterion to decide whether to use stdin. That''s
the typical unix approach: "cat" reads stdin only if it doesn''t have
any filename arguments; it doesn''t try to determine whether reading
stdin would block.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


Nikos Chantziaras写道:
Nikos Chantziaras wrote:

你好。


有没有办法检查当前进程是否有stdin句柄?在

win32 API中,可以做到:


_eof(_fileno(stdin))


至关重要是上面没有阻止。有没有标准的方式

来做同样的事情而不诉诸OS特定的API调用?
Hello.

Is there a way to check if the current process has an stdin handle? In
the win32 API, one can do:

_eof(_fileno(stdin))

Crucial here is that the above doesn''t block. Is there a standard way
to do the same without resorting to OS-specific API calls?



三个标准流,stdin,stdout和stderr总是打开,并且当标准C程序开始执行时初始化
。它可能会关闭

或重新打开它们。在

程序中的任意位置都无法确定stdin是打开还是连接到输入

设备。如果你关闭或重新打开stdin,你必须自己手动跟踪这个细节。


任何特定于系统的方法都是局部的分组用于那些

系统,而不是这里。

A three standard streams, stdin, stdout, and stderr are always opened and
initialised when a Standard C program begins execution. It might then close
or reopen them. It''s not possible in an arbitrary position within the
program to find out whether stdin is open or is connected to the input
device. If you close or reopen stdin, you''ll have to manually keep track of
this detail yourself.

Any system specific methods to do this are topical in groups for those
systems, not here.


这篇关于检查进程是否有stdin句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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