473,587 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recording messages and print statements in a textfile during programexecutio n.

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 2398
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(stdo utstream,stderr stream=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("exa mple2.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.String IO()
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
7375
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 atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover -...
14
2899
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: $Revision: 0.0 $
0
1320
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 messages in each functions. May be use Emit or something. Is there any tool out there that could instrument my methods with a pre and post statements...
2
7407
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 the Query Analyser. Is there a way or getting these messages in vb.net. Ive had a look round but no one seems to have done it before. I suppose i...
0
1437
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' RAISERROR(@err, 16, 1, 1) RETURN The exception type thrown is a System.Data.SqlClient.SqlException, and its message property holds the exception text....
2
22858
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 openning, fetching, and closing of a cursor. Things are fine if only one of the two parameters was set to 1. When run with both parameters...
1
1337
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 many records that it updated as well as the number of records that were not updated. Right now I have all of my queries coded into a form that...
2
19443
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.