473,416 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Recording messages and print statements in a textfile during programexecution.

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
1 2384
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
0
by: High and dRy | last post by:
Print debug messages at the beginning of all the methods with the method name and the argument values and at the end with the return values. Is it possible to do the in C# without writing debug...
2
by: James Proctor | last post by:
Hi There, I have written an SQL script which i run though a VB.net application. It has some print statements in which print results of the Script to the message window if you run the script in...
0
by: Paul | last post by:
Occasionally my users will try to perform an action and be presented with an exception raised directly from SQL Server, in example: SET @err = 'a user-friendly error condition message'...
2
by: Bill_DBA | last post by:
I have the following stored procedure that is called from the source of a transformation in a DTS package. The first parameter turns on PRINT debug messages. The second, when equals 1, turns on the...
1
by: Bill | last post by:
I'm looking for a way to output the text that is displayed when a warning is displayed from running a query into a table or a text file. It's my intent to have a log of when a query was run and how...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.