3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Can you give steps to reproduce the problem? (I cannot reproduce it. I tried math -run 'WriteString["stdout", 123]; Pause[5]; Quit[]') $\endgroup$
    – Szabolcs
    Dec 19, 2016 at 16:57
  • $\begingroup$ 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 :). $\endgroup$
    – Ben Farmer
    Dec 20, 2016 at 9:14
  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Dec 22, 2016 at 12:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.