3
$\begingroup$

I have difficulties with session logging and Mathematica 10. In previous versions, you could simply use AppendTo[$Echo, logfile] and AppendTo[$Output, logfile].

In Mathematica 10, appending to $Echo only works for cells in raw input format, as stated in the reference.

Appending to $Output seems not working. Log file is always empty.

My questions:

a) How can I force all input cells to be in "raw input format", without converting the cells by the menu?

b) What's wrong with my AppendTo[$Output]?

oldout = $Output;
logfile = OpenWrite[FileNameJoin[{$TemporaryDirectory, "math.log"}],
    FormatType -> InputForm];
AppendTo[$Output, logfile];
AppendTo[$Echo, logfile];
First@logfile

(* tests, $Echo works, if cell is converted to raw input format *)
2+2
Expand[(a + b)^3]
Factor[z^5 - 1]
N[Pi, 24]
Close[logfile];
$Echo={};
$Output = oldout;
FilePrint[First@logfile]
$\endgroup$

1 Answer 1

2
$\begingroup$

Try Wolfram Language Script this is a new thing...

https://reference.wolfram.com/language/tutorial/WolframLanguageScripts.html

Put your code in a .wl plain text file:

Solve[x^2+3x+2==0,x]


2+2
Expand[(a+b)^3]
Factor[z^5-1]
N[Pi,24]
7/0

and then runs like this:

> wolframscript -print all -file s1.wl
{{x -> -2}, {x -> -1}}
4
a^3 + 3*a^2*b + 3*a*b^2 + b^3
(-1 + z)*(1 + z + z^2 + z^3 + z^4)
3.1
41592                                 1
Power::infy: Infinite expression - encountered.
                                 06
5358979323846264338327950288582`24.
ComplexInfinity
$\endgroup$

Your Answer

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

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