473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

can we save print msg into a file when script running ?

hi all~

in my .py file there are a few print to trace out some message and i
wonder if we can save it into a specified file when that script get
running. if so, i may just check that file to c how the script is
running. can anyone show me a right direction ?

one million tks~

Oct 12 '05 #1
7 1534
black wrote:
hi all~

in my .py file there are a few print to trace out some message and i
wonder if we can save it into a specified file when that script get
running. if so, i may just check that file to c how the script is
running. can anyone show me a right direction ?

one million tks~

On Unix platforms you can run your script with a redirection of the
standard output:

python myscript.py > somefile.txt &

[The ampersand runs the command in the background]. Then you can monitor
the content of the output file with

tail -f somefile.txt

which will show you the last part of the file and further additions as
long as you let the tail command run.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 12 '05 #2
black wrote:
hi all~

in my .py file there are a few print to trace out some message and i
wonder if we can save it into a specified file when that script get
running. if so, i may just check that file to c how the script is
running. can anyone show me a right direction ?

one million tks~


script.py >> script.log 2>&1

--
Best regards,
Maksim Kasimov
mailto: ma************@gmail.com
Oct 12 '05 #3
unluckly i am with windows, anyway tks !

Oct 12 '05 #4
quote:
=======================
script.py >> script.log 2>&1
=======================

what does 2>&1 mean pls ?

Oct 12 '05 #5
black wrote:
in my .py file there are a few print to trace out some message and i
wonder if we can save it into a specified file when that script get
running. if so, i may just check that file to c how the script is
running. can anyone show me a right direction ?


If you don't feel comfortable with the command line you can stick

import sys
sys.stdout = open("mylogfile.txt", "w")

at the beginning of your file.

Peter

Oct 12 '05 #6
black wrote:
quote:
=======================
script.py >> script.log 2>&1
=======================

what does 2>&1 mean pls ?

It's Unix shell-speak for "send the standard error stream to the same
place as the standard output". Probably a syntax error on Windows ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 12 '05 #7
Steve Holden wrote:
what does 2>&1 mean pls ?
It's Unix shell-speak for "send the standard error stream to the same
place as the standard output". Probably a syntax error on Windows ...

more test.py import sys
sys.stdout.write("stdout!\n")
sys.stderr.write("stderr!\n")
python test.py >out stderr!
python test.py 2>out stdout!
python test.py >out 2>&1
more out stdout!
stderr!
ver

Microsoft Windows XP [Version 5.1.2600]

</F>

Oct 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Florian Lindner | last post by:
Hello, I've a scripts that allows limited manipulation of a database to users. This script of course needs to save a password for the database connection. The users, on the other hand need read...
6
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of...
2
by: Kitkat | last post by:
Hi, i hope my english is good enough to explain my problem. Okay, I have a html-file with a image. But i don't want to save or print the html-file with the image. I want to save or print a...
5
by: Poster | last post by:
I have a script, its outputs are in HTML. It displays perferctly in a browser, however when I view source, it gives me the JS scripts, but I want to view the HTML output. Is there a way I can view...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
0
by: lety28 | last post by:
I have a script "licence.cgi" write in python which generate text files and I would like that the user click on a button and he can download this file. _1er solution:_ I found in my research that...
3
by: Max58kl | last post by:
Trying to access data and print it to the screen using Perl Builders I/O Window -------------------------------------------------------------------------------- Hi I am using a program called...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
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
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
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.