你可以做一个fstat http://man7.org/linux/man-pages/man2/stat.2.html文件描述符并检查返回结构,例如,st_mode
= 0x1000 (S_IFIFO) 表示命名管道。
使用 Python 的示例:
from __future__ import print_function
import sys
import os
print(os.fstat(sys.stdout.fileno()), file=sys.stderr)
Windows 上的输出:
C:> python test_fd.py | more
nt.stat_result(st_mode=4096, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=0L, st_mtime=0L, st_ctime=0L)
C:> python test_fd.py > test_fd.txt
nt.stat_result(st_mode=33206, st_ino=16888498602769633L, st_dev=0, st_nlink=1, st_uid=0, st_gid=0, st_size=0L, st_atime= 1401119520L, st_mtime=1401119520L, st_ctime=1401119349L)