4
$\begingroup$

Testing this answer I used:

stream = OpenWrite["A:\\out.txt"];

Block[{$Messages = stream},
  Mod[1, 2, 3, 4, 5]
]

and I was surprised to find that the contents of out.txt read:

Intersection::normal: 
   Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[
    Intersection[{StandardForm, TraditionalForm}, FormatType]
    , "MT"]\)\[NoBreak]. >>

Intersection::normal: 
   Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[
    Intersection[{StandardForm, TraditionalForm}, FormatType]
    , "MT"]\)\[NoBreak]. >>

Intersection::normal: 
   Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[
    Intersection[{StandardForm, TraditionalForm}, FormatType]
    , "MT"]\)\[NoBreak]. >>

General::stop: Further output of \[NoBreak]\!\(\*StyleBox[Intersection::normal
    , "MT"]\)\[NoBreak] will be suppressed during this calculation. >>

Options::optnf: 
   \[NoBreak]\!\(\*StyleBox[FormatType
    , "MT"]\)\[NoBreak] is not a known option for \[NoBreak]\!\(\*StyleBox[
    Intersection[OutputStream[A:\out.txt, 12], 
     {OutputStream[stdout, 1], OutputStream[stderr, 2], 
      OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. >>

Options::optnf: 
   \[NoBreak]\!\(\*StyleBox[FormatType
    , "MT"]\)\[NoBreak] is not a known option for \[NoBreak]\!\(\*StyleBox[
    Intersection[OutputStream[A:\out.txt, 12], 
     {OutputStream[stdout, 1], OutputStream[stderr, 2], 
      OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. >>

Options::optnf: 
   \[NoBreak]\!\(\*StyleBox[FormatType
    , "MT"]\)\[NoBreak] is not a known option for \[NoBreak]\!\(\*StyleBox[
    Intersection[OutputStream[A:\out.txt, 12], 
     {OutputStream[stdout, 1], OutputStream[stderr, 2], 
      OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. >>

General::stop: Further output of \[NoBreak]\!\(\*StyleBox[Options::optnf
    , "MT"]\)\[NoBreak] will be suppressed during this calculation. >>

Intersection::heads: 
   Heads \[NoBreak]\!\(\*StyleBox[List
    , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream
    , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1
    , "MT"]\)\[NoBreak] are expected to be the same. >>

Intersection::heads: 
   Heads \[NoBreak]\!\(\*StyleBox[List
    , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream
    , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1
    , "MT"]\)\[NoBreak] are expected to be the same. >>

Intersection::heads: 
   Heads \[NoBreak]\!\(\*StyleBox[List
    , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream
    , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1
    , "MT"]\)\[NoBreak] are expected to be the same. >>

General::stop: Further output of \[NoBreak]\!\(\*StyleBox[Intersection::heads
    , "MT"]\)\[NoBreak] will be suppressed during this calculation. >>

Mod::argt: \[NoBreak]\!\(\*StyleBox[Mod
    , "MT"]\)\[NoBreak] called with \[NoBreak]\!\(\*StyleBox[5
    , "MT"]\)\[NoBreak] arguments; \[NoBreak]\!\(\*StyleBox[2
    , "MT"]\)\[NoBreak] or \[NoBreak]\!\(\*StyleBox[3
    , "MT"]\)\[NoBreak] arguments are expected. >>

I expected only the last message. This looks like the result of a misconfiguration or Style Sheet problem but I don't know what it is.

Do others get these messages? If yes, what is the explanation? If not, what might I have done to cause this?

$\endgroup$
  • 3
    $\begingroup$ You should re-read the usage message for $Messages very carefully. $\endgroup$ – Brett Champion Feb 1 '12 at 18:08
  • $\begingroup$ @Brett actually I didn't read it at all; I trusted Szabolcs. I blame him! $\endgroup$ – Mr.Wizard Feb 1 '12 at 18:12
  • $\begingroup$ To clarify a bit the somewhat cryptic answer of @Brett - $Messages point to a channel, which can be a list of streams, but not a single stream without a list around it. $\endgroup$ – Leonid Shifrin Feb 1 '12 at 18:13
  • $\begingroup$ @LeonidShifrin Don't answer in comments! $\endgroup$ – Brett Champion Feb 1 '12 at 18:16
  • 2
    $\begingroup$ @Brett Did not indend to. This was your answer, I just commented on it :). Why don't you put this as an answer? $\endgroup$ – Leonid Shifrin Feb 1 '12 at 18:16
6
$\begingroup$

The documentation for $Messages clearly states:

$Messages gives the list of files and pipes to which message output is sent.

Therefore Block[{$Messages = {stream}}, ... ] is the correct syntax.

$\endgroup$

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.