Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to construct a text-file that contains all the operations that Mathematica performs when evaluating an expression. However, i'd like to suppress all output in the notebook in which I'm doing the calculations.

For instance printing the operations for calculating the root of x^2 = 1 in Mathematica.txt is done as follows:

stream = OpenWrite["c:/Data/Mathematica.txt"];
AppendTo[$Output, stream];
Print[TracePrint[Solve[x^2 == 1, x]]];
Close[stream];
$Output = Most[$Output];

which gives the following output in my Notebook:

Solve[x^2==1,x]    
Solve  
x^2==1    
Equal    
(x^2)     
Power 
x
2
1 
x 
x^2==1
x^2==1
{{x->-1},{x->1}}
{{x->-1},{x->1}}

and the following output in Mathematica.txt

 HoldForm[Solve[x^2 == 1, x]]
  HoldForm[Solve]
  HoldForm[x^2 == 1]
   HoldForm[Equal]
   HoldForm[x^2]
    HoldForm[Power]
    HoldForm[x]
    HoldForm[2]
   HoldForm[1]
  HoldForm[x]
  HoldForm[x^2 == 1]
  HoldForm[x^2 == 1]   
 HoldForm[{{x -> -1}, {x -> 1}}]
{{x -> -1}, {x -> 1}}

Is there a way to not get the first block of 'output'?

Thanks a lot!

share|improve this question
    
Hello @Valkyrie and welcome to the Mathematica StackExchange. Don't forget to upvote good answers (and other people's questions), and use the checkmark to "accept" the answer to your question that you think best answers it. Also, take some time to read the about where there's a lot of useful info on how the site operates. –  gpap Oct 31 '13 at 15:15
add comment

1 Answer

up vote 0 down vote accepted

This might work:

oldout = $Output; stream = OpenWrite["c:/Data/Mathematica.txt"]; $Output = stream;
Write[stream, TracePrint[Solve[x^4 == 1, x]]];
Close[stream]; $Output = oldout;

The concept is to redirect the output to your file and than recover the original output stream.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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