关于haskell程序的问题 cygwin 中的标准输出缓冲区
我有一个简单的 haskell 程序,它会
- 用 '\n' 向用户提示一些消息
- 等待用户输入
- 打印用户的输入
如果我从命令提示符或从命令提示符启动的 cygwin shell 启动程序,那就没问题。
但是,如果我从连接到本地 cygwin 环境的 ssh shell 启动程序,则程序在退出之前不会将任何内容写回到终端。看起来 ssh shell 中 STDOUT 的缓冲区不是行缓冲而是块缓冲。
我不想手动冲水。我该如何解决这个问题?
I have a simple haskell program, which do
- prompt some message to user, with '\n'
- waiting for user input
- print user's input
If I launch the program from a command prompt or from a cygwin shell which is launched from a command prompt, it is ok.
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.
I don't want to flush manually. How do I fix the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据推测,您的 Haskell 程序不是 Cygwin 程序,即它未链接到 Cygwin DLL。 SSH 连接在服务器端分配一个所谓的伪终端 (pty) 设备,Cygwin 使用 Windows 管道实现该设备。非 Cygwin 程序只能看到管道,而它们可能期望与 Windows 控制台窗口对话。缓冲问题是其可能的后果之一。请参阅此帖子以获取进一步的说明和可能的解决方法:http://code.google .com/p/mintty/issues/detail?id=56。
Presumably your Haskell program isn't a Cygwin program, i.e. it isn't linked against the Cygwin DLL. SSH connections allocate a so-called pseudo terminal (pty) device on the server side, which Cygwin implements using Windows pipes. Non-Cygwin programs only see the pipes, whereas they might expect to be talking to a Windows console window. Buffering issues are one possible consequence of that. See this thread for further explanation and possible workarounds: http://code.google.com/p/mintty/issues/detail?id=56.
您可以手动将缓冲模式设置为您需要的模式:
有关更多信息,请参阅 System.IO.hSetBuffering。
You can manually set the buffering mode to the one you need:
For more information see System.IO.hSetBuffering.
您没有说明如何在 ssh 下启动程序。
如果您在单个步骤中执行此操作,例如
,则可能没有分配终端,这通常会导致程序的输出被块缓冲而不是行缓冲。
您可以通过使用
-t
切换到ssh
来避免这种情况(请检查您的手册以确保):另一方面,如果您将 ssh 作为单独的步骤进行登录启动您的程序
,那么这不太可能是原因。
You don't say how you are launching your program under ssh.
If you are doing it in a single step, e.g.
then it is possible that a terminal is not being allocated, which would generally cause your program's output to be block buffered instead of line buffered.
You can avoid this by using the
-t
switch tossh
(check your manual to be sure):If, on the other hand, you are sshing in as a separate step to launching your program
then this is unlikely to be the cause.