I presume you are writing the program, say prog.sage, and running it as
$ sage prog.sage
Am I correct? If so, then you can write your program like this. You can
force printing the output by using sys.stdout.flush():
import sys
p = 3
while true:
p = p.next_prime()
print p
sys.stdout.flush() % force printing of output.
Then you can run the program in two ways:
Method 1:
---------
$ sage prog.sage < infile.txt | tee output_file.txt
Method 2:
---------
If you are running it in the background like this:
$ sage prog.sage &
then instead run it as
$ sage prog.sage <infile.txt > output_file.txt 2>&1 &
The Method 2 is not very convenient though. So, my suggestion would be
to run as in Method 1, but run it inside screen.
http://en.wikipedia.org/wiki/GNU_Screen
http://aperiodic.net/screen/quick_reference
On 11/15/2012 05:56 PM, Zhibin Liang wrote:
Dear all,
I try to send this email to sage-support but I don't have the right to
do that. Hence I send to the group of number theory. I am sorry to
interrupt you.
---------- Forwarded message ----------
From: *Zhibin Liang* <liang...@gmail.com <mailto:liang...@gmail.com>>
Date: 2012/11/15
Subject: On saving data when programm is running
To: sage-support <sage-support@googlegroups.com
<mailto:sage-support@googlegroups.com>>
Dear All,
I have a basic problem on running sage.
When I am running a programme on background, I want to output some data
before the end of programme in one file(ex, a txt file).
For example, I saved the following code as file A
########################
p=3
while true:
p=p.next_prime()
################################
It will never stop but I want to see which all p it come at present.
If we write
sage<file A>file B&;
Then there is nothing on file B unitil the end of the programme(but
time is infinity)
I also tried
########################
p=3
outfile=file B
while true:
p=p.next_prime()
outfile.write(str(p))
################################
But the new p will cover the old p in file B.
Can I write some output command to realise my desire?
Very best wishes
ZHibin Liang
--
Very best wishes
Zhibin Liang
Building 104 Room 103
Nanhudongyuanyiqu
Wangjing, Chaoyang District
Beijing China,
100102
--
Very best wishes
Zhibin Liang
Building 104 Room 103
Nanhudongyuanyiqu
Wangjing, Chaoyang District
Beijing China,
100102
--
You received this message because you are subscribed to the Google
Groups "sage-nt" group.
To post to this group, send an email to sage...@googlegroups.com.
To unsubscribe from this group, send email to
sage-nt+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sage-nt?hl=en-GB.
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.