4
$\begingroup$

Does Mathematica provide any way to print text to the terminal without a newline at the end when running in command line mode? There are many workarounds with the notebook interface, but this question is specifically about the command line.

I would like to use this for more detailed progress monitoring on a headless machine. The only solution I could think of so far is using LibraryLink to do the printing, which isn't that bad actually as I do already have a LibraryLink component in this program.

To sum up, I want a print function so that

Do[Pause[1]; print["."], {5}]

produces

.....

in a terminal session and the dots appear gradually.

$\endgroup$
3
$\begingroup$

It seems my question was premature. This can be done by writing to stdout using WriteString.

Notice that stdout is open as a stream:

In[13]:= Streams[]                                                              
Out[13]= {OutputStream[stdout, 1], OutputStream[stderr, 2]}

We can simply use

Do[WriteString[OutputStream["stdout",1] ,"."], {5}]

This works on OS X and Linux. I haven't tried on Windows.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Works on Windows too. $\endgroup$ – user31159 Sep 15 '16 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.