1

I have a simple haskell program, which do

  1. prompt some message to user, with '\n'
  2. waiting for user input
  3. 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?

Landei
  • 52,346
  • 12
  • 89
  • 188
redtank
  • 61
  • 5

3 Answers3

3

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.

ak2
  • 6,262
  • 27
  • 23
2

You can manually set the buffering mode to the one you need:

import System.IO

main = do
  hSetBuffering stdout LineBuffering
  hSetBuffering stdin LineBuffering

For more information see System.IO.hSetBuffering.

nominolo
  • 5,005
  • 1
  • 22
  • 31
1

You don't say how you are launching your program under ssh.

If you are doing it in a single step, e.g.

ssh localhost myprogram

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 to ssh (check your manual to be sure):

ssh -t localhost myprogram

If, on the other hand, you are sshing in as a separate step to launching your program

ssh localhost
myprogram

then this is unlikely to be the cause.

dave4420
  • 44,728
  • 6
  • 108
  • 146