424,279 Members | 1,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,279 IT Pros & Developers. It's quick & easy.

Recording messages and print statements in a textfile during programexecution.

P: n/a
Recording messages and print statements in a textfile during program
execution.
Is there a similar command to redirect errormessages or print statements
into a standart asciifile during programm execution.
I would like to echo the complete console output into a textfile and
send this file as email at a certain point in time.
The programm execution shall not be stopped.

As an example take a look at the description below. Set alternate on is
a command from the programming language clipper / dbase / flagship
Manfred


SET ALTERNATE
Echo console output to a text file
------------------------------------------------------------------------------

Syntax

SET ALTERNATE TO [<xcFile> [ADDITIVE]]
SET ALTERNATE on | OFF | <xlToggle>

Arguments

TO <xcFile> opens a standard ASCII text file for output with a
default extension of (.txt). The filename may optionally include
an
extension, drive letter, and/or path. You may specify <xcFile>
either
as a literal filename or as a character expression enclosed in
parentheses. Note that if a file with the same name exists, it is
overwritten.

ADDITIVE causes the specified alternate file to appended to instead

of overwritten. If not specified, the specified alternate file is
truncated before new information is written to it.

ON causes console output to be written to the open text file.

OFF discontinues writing console output to the text file without
closing the file.

<xlToggle> is a logical expression that must be enclosed in
parentheses. A value of true (.T.) is the same as ON, and a value
of
false (.F.) is the same as OFF.

Description

SET ALTERNATE is a console command that lets you write the output
of
console commands to a text file. Commands such as LIST, REPORT
FORM,
LABEL FORM, and ? that display to the screen without reference to
row
and column position are console commands. Most of these commands
have a
TO FILE clause that performs the same function as SET ALTERNATE.
Full-screen commands such as @...SAY cannot be echoed to a disk
file
using SET ALTERNATE. Instead you can use SET PRINTER TO <xcFile>
with
SET DEVICE TO PRINTER to accomplish this.

SET ALTERNATE has two basic forms. The TO <xcFile> form creates a
DOS
text file with a default extension of (.txt) and overwrites any
other
file with the same name. Alternate files are not related to work
areas
with only one file open at a time. To close an alternate file, use

CLOSE ALTERNATE, CLOSE ALL, or SET ALTERNATE TO with no argument.

The on|OFF form controls the writing of console output to the
current
alternate file. SET ALTERNATE ON begins the echoing of output to
the
alternate file. SET ALTERNATE OFF suppresses output to the
alternate
file but does not close it.

Examples

. This example creates an alternate file and writes the results
of the ? command to the file for each record in the Customer
database
file:
# determine outputfile
SET ALTERNATE TO Listfile

# start recording
SET ALTERNATE ON

USE Customer NEW
DO WHILE !EOF()
? Customer->Lastname, Customer->City
SKIP
ENDDO

# stop recording
SET ALTERNATE OFF

# close recordfile
CLOSE ALTERNATE
CLOSE Customer

Files: Library is CLIPPER.LIB.

--
This e-mail may contain trade secrets or privileged, undisclosed or
otherwise confidential information. If you are not the intended
recipient and have received this e-mail in error, you are hereby
notified that any review, copying or distribution of it is strictly
prohibited. Please inform us immediately and destroy the original
transmittal from your system. Thank you for your co-operation.

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Am Donnerstag, 16. September 2004 12:36 schrieb Manfred Schwab:
Recording messages and print statements in a textfile during program
execution.


Example:

<file name="redirect.py">
import sys

_originalStdout = sys.stdout
_originalStderr = sys.stderr

def redirectTo(stdoutstream,stderrstream=None):
sys.stdout = stdoutstream
sys.stderr = stderrstream or stdoutstream

def resetRedirect():
sys.stdout = _originalStdout
sys.stderr = _originalStderr
</file>

<file name="example1.py">
from redirect import *

redirectTo(file("example1.log","w"))
print "This is a test logging message."
print "Yet another one."
raise RuntimeError, "and this error will also be logged to the file."
</file>

<file name="example2.py">
from redirect import *

redirectTo(file("example2.log","w"),file("example2 .error-log","w"))
print "This will be written to example2.log"
raise RuntimeError, "This error message is written to example2.error-log"
</file>

<file name="example3.py">
from redirect import *
import StringIO

x = StringIO.StringIO()
redirectTo(x)
print "This message will appear in the string buffer."
print "This message will also appear in the string buffer."

# Do something with x.
file("example3.log","w").write(x.uppercase())

# Reset redirection.
resetRedirect()

print "This message will appear on screen."
print "This message too."
raise RuntimeError, "This error will also appear on screen."
</file>

HTH!

Heiko.
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.