By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,368 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,368 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
unluckly i am with windows, anyway tks !

Oct 12 '05 #4

P: n/a
quote:
=======================
script.py >> script.log 2>&1
=======================

what does 2>&1 mean pls ?

Oct 12 '05 #5

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.