3

I am aware that one can write to a terminal standard output like so:

WriteString["stdout","Some stuff","\r"];

Note here that I am using a carriage return on purpose, as part of some output monitoring. However, sometimes the output gets a bit messed up because it seems like stdout doesn't always update on the carriage return. I've seen this kind of thing before in C++ for example, and there I usually solve it by flushing the stdout stream. But I don't know how to do that, or anything analogous, in Mathematica. Help? :).

I am in a Linux environment, in case that matters.

Ben Farmer
  • 193
  • 6
  • Can you give steps to reproduce the problem? (I cannot reproduce it. I tried math -run 'WriteString["stdout", 123]; Pause[5]; Quit[]') – Szabolcs Dec 19 '16 at 16:57
  • Well I am doing something more like this, although this example also seems to work fine: math -run 'Table[Table[WriteString["stdout", "blah blah "<>ToString[i]<>" "<>ToString[j]<>" ","\r"],{i,1,10000}],{j,1,10000}]; Quit[]'. I am not sure what causes the issue in my larger code. Maybe it is even related to my exact terminal environment or something. I guess my question stands independently of the exact problem though :). – Ben Farmer Dec 20 '16 at 09:14
  • I was asking because I don't think that you will get any answer unless you can show a reproducible example. Personally, I was under the impression that WriteString flushes right away. If this is not true, I would like to see it, so I can avoid problems in the future. I did search a bit about this topic a while ago (before your question), and I found nothing. Also, what actually happens depends on how you run Mathematica. If you use the new-in-11 wolframscript, the behaviour may be entirely different. I am not sure about the older script mode. – Szabolcs Dec 22 '16 at 12:35

0 Answers0