Page 1 of 1

Output not flushed if not TTY

Posted: 19 Feb 2014, 05:47
by MiniGod
This post is to:
  • give people (advanced users, i guess) a workaround if they have ever encountered this problem.
  • ask why it is like this...
If I don't run the the server in a TTY context, there's no output until the server exits.
Simplest way for you to see it for your self is to run: (notice that there is no output until it exits)

Code: Select all

 ./ManiaPlanetServer /nodaemon | cat 
Since the output is piped, its not in a TTY context.
`cat` is a stupid use case, but you could for instance pipe it to a log service, like loggly.

Why do I want to run it without TTY?
  • pipe - some log services (eg, loggly) have clients you can pipe to to send to them. `./ManiaPlanetServer /nodaemon | loggly-pipe` - or use `awk` to format the lines differently before writing to disk - many possibilities
  • child_process in node.js - running a server as child_process under node.js, and getting a stream of the console could allow for some cool ideas for GSP's.
  • docker.io - magic
There are workarounds, so there is no panic. But I feel like its silly to be needed to run it like this:

Code: Select all

script -qc "./ManiaPlanetServer /nodaemon" /dev/null | cat
With docker, you can add the -t flag, which is not so bad.

To summarize:
What is the reason for not flushing output when not in a TTY context?
And if people has had this issue, and haven't found a workaround. Well... now you have a workaround. (took me a long time to find it)

Re: Output not flushed if not TTY

Posted: 19 Feb 2014, 20:55
by TMarc
nice :thumbsup:

there is also tee and mtee which allows to see both the output and log to a file at the same time.

Re: Output not flushed if not TTY

Posted: 19 Feb 2014, 21:55
by MiniGod
Good example TMark.

But as of now, you can't really use those tools without a workaround similar to what I described, because there is no output piped from the server until it exits.

Re: Output not flushed if not TTY

Posted: 19 Feb 2014, 22:37
by TMarc
Did you check if the logfiles get written and updated constantly?
Logs/GameLog.txt and Logs/ConsoleLog.txt

Re: Output not flushed if not TTY

Posted: 20 Feb 2014, 00:42
by MiniGod
The log files are written just fine.