def readStdin(self):
app.log.info('reading from stdin')
# Create a new input stream for the file data.
# Fd is short for file descriptor. os.dup and os.dup2 will duplicate file
# descriptors.
stdinFd = sys.stdin.fileno()
newFd = os.dup(stdinFd)
newStdin = open("/dev/tty")
os.dup2(newStdin.fileno(), stdinFd)
# Create a text buffer to read from alternate stream.
textBuffer = self.newTextBuffer()
try:
with io.open(newFd, "r") as fileInput:
textBuffer.fileFilter(fileInput.read())
except Exception as e:
app.log.exception(e)
app.log.info('finished reading from stdin')
return textBuffer
评论列表
文章目录