Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Fwd: On saving data when programm is running
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
P Purkayastha  
View profile  
 More options Nov 15 2012, 6:49 am
From: P Purkayastha <ppu...@gmail.com>
Date: Thu, 15 Nov 2012 19:46:01 +0800
Local: Thurs, Nov 15 2012 6:46 am
Subject: Re: Fwd: On saving data when programm is running
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-nt@googlegroups.com.
> To unsubscribe from this group, send email to
> sage-nt+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sage-nt?hl=en-GB.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.