关于haskell程序的stdout缓冲区在cygwin的问题 [英] Question about haskell programs' stdout buffer in cygwin
问题描述
我有一个简单的haskell程序,它
I have a simple haskell program, which do
- 提示一些消息给用户,用'\\\
'
- 等待用户输入
- 打印用户输入
- prompt some message to user, with '\n'
- waiting for user input
- print user's input
如果我从命令提示符或从cygwin shell启动程序这是从命令提示符启动,它是确定。
If I launch the program from a command prompt or from a cygwin shell which is launched from a command prompt, it is ok.
但是如果我从连接到本地cygwin环境的ssh shell启动程序,程序在退出之前不会将任何东西写回终端。看起来像ssh shell中STDOUT的缓冲区不是行缓冲的,而是块缓冲的。
But if I launch the program from ssh shell which is connected to a local cygwin environment, the program don't write anything back to terminal until it exit. It looks like the buffer for STDOUT in ssh shell is not line buffered but block buffered.
我不想手动刷新。
推荐答案
您可以手动将缓冲模式设置为所需的缓冲模式:
You can manually set the buffering mode to the one you need:
import System.IO
main = do
hSetBuffering stdout LineBuffering
hSetBuffering stdin LineBuffering
有关详细信息,请参阅 System.IO.hSetBuffering 。
For more information see System.IO.hSetBuffering.
这篇关于关于haskell程序的stdout缓冲区在cygwin的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!