Redirection problem
half.italian at gmail.com
half.italian at gmail.com
Mon Apr 23 12:49:58 EDT 2007
On Apr 23, 9:10 am, CSUIDL PROGRAMMEr <syedamja... at yahoo.com> wrote:
> I am new to python. so be patient with me
>
> I am trying to redirect the output of os.popen command to a file. I
> want to append to that file. but instead of appending. The file only
> shows last command that was writtenn to it.
>
> filehandle= open("/root/yhpc-2.0/installer/yhpc-log" ,"a+");
> filehandle.write(" Command executed is " + cmd);
> try:
> pipe= os.popen('%s > /root/yhpc-2.0/installer/yhpc-log' %cmd );
> except : IOError;
> filehandle.close();
>
> Any suggestion would help.
>
> filehandle.close();
This works.
f = open("test", 'a')
stdout = os.popen("ls -l /")
f.write(stdout.read())
f.close()
~Sean
More information about the Python-list
mailing list