473,217 Members | 2,099 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,217 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 2370
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
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.