MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Save print in textfile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15556] Re: Save print in textfile
  • From: Emmanuel.Peccoud at e-notebooks.com (Emmanuel Peccoud)
  • Date: Tue, 26 Jan 1999 13:44:38 -0500 (EST)
  • Organization: e-NoteBooks Ltd.
  • References: <7814h5$p1v@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

wgrebe <wgrebe at cityweb.de> wrote:

> Hallo,
> 
> I want to save the result of a series of Print commands in a textfile.
> For example:
> df=Do[
> Print["sample: ",name];
> Print["___________________________________"]; Print[" conditions: "
> number];
> Print["___________________________________"]; ];
> results in the output:
> 
> sample: aab
> ___________________________________
> conditions: 34
> ___________________________________
> 
> This output I want to have in the file "textfile.txt" in the directory
> C:\temp.
> Thank you
>                             Witold
> wgrebe at cityweb.de

Print is directed to the $Output stream. You can redefine this stream to
a file of your choice. 
 

In[15]:=
$Output = OpenWrite["C:\\temp\\ textfile.txt", FormatType -> OutputForm]
Out[15]=
OutputStream["print.txt",6]

This command redirects $Output to a file named "textfile.txt" in the
temp directory.

In[16]:=
Print[whatever]


In[17]:=
Print[anything]

Print whatever you need. Print each item will be placed on a new line.

In[18]:=
Close at $Output
Out[18]=
"textfile.txt"

Don't forget to close the stream when you are done. This can easily be
integrated in a package.

You could achieve similar results using the Put instruction (>>) which
would save you the hassle of opening and closing the stream.

I hope this helps.
_________________
Emmanuel Peccoud
e-Notebooks Ltd.
Visit our web site at http://www.e-notebooks.com


  • Prev by Date: Re: Special characters
  • Next by Date: Re: Save print in textfile
  • Previous by thread: Re: Save print in textfile
  • Next by thread: Re: Save print in textfile