Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- flushing stdout
March 4, 2005, 10:51 am
rate this thread
Using the default ssh on Mac OS X 10.3.8, which is
"OpenSSH_3.6.1p1+CAN-2004-0175, SSH protocols 1.5/2.0, OpenSSL
0x0090702f" to run an interactive program over SSH, stdout is not
getting flushed through until the connection is closed, although stderr
is working just fine. Can anybody please tell me what to do about this?
I'm not any non-default features such as compression.
$ cat test.c
int main(int argc, char **argv)
$ cat test2.c
int main(int argc, char *argv)
char *cp = c;
while ((cp = fgets(c, 63, stdin)))
fprintf(stdout, "(stdout) %s\n", cp);
fprintf(stderr, "(stderr) %s\n", cp);
[^D] $ ssh localhost ./test
$ ssh localhost ./test2
Re: flushing stdout
This doesn't really have anything to do with ssh, but is the standard
behaviour of the Unix/POSIX stdio library. Stdout isn't flushed until
some "big" number of characters are buffered - or, if stdin/out is a
tty, when a read request is issued for stdin.
When you run 'ssh <host> <cmd>', the stdin/out of <cmd> isn't a tty but
a socket, so the the second case doesn't apply. Either you can write
your program to flush stdout at appropriate points (or have it
unbuffered or line buffered), or you can use ssh's -t option (assuming
OpenSSH) to provide a pseudo tty for <cmd>.
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — Newest thread in » Secure Shell Forum