[Tutor] os.popen

Klas Marteleur klas.martelleur at telia.com
Mon Nov 29 17:30:13 CET 2004


hmm..
Is it nesessary to close the "file objects"?

a = os.popen3("tcextract -v")
tcexVerOut= a[2].readlines() 
a[0].close() #Nesessary?
a[1].close() #Nesessary?
a[2].close() #Nesessary?

Regards Klas


> Ok i used popen3 instead, reading the "child-stderr" instead and it worked.
>
> >>> tcextract = os.popen3("tcextract -v")
> >>> tcextract[2].readlines()
>
> ['tcextract (transcode v0.6.12) (C) 2001-2003 Thomas Oestreich\n']
>
> Thanks Hugo
>
> Regards Klas
>
> söndagen den 28 november 2004 19.26 skrev du:
> > Hi Klas,
> >
> > Maybe the output you're trying to get is in STDERR and not STDOUT?? I've
> > had to deal with this a number of times, so may I wrote a Tkinter script
> > to let me know what output is to STDERR and what is to STDOUT. os.popen
> > will open STDOUT if invoked with "r" (which is the default).
> >
> > Try looking of other popen* functions. They provide STDOUT + STDERR
> > (popen4) or separate STDOUT + STDERR (popen3)
> >
> > BTW< if you'd like to have my script (the Streamshower, I call it =) )
> > just email me ...
> >
> > Hugo
> >
> > Klas Marteleur wrote:
> > > Hi
> > > I have a little problem that is confusing me.
> > >
> > > If i write the following in a bash shell i get the desired output:
> > > [klas at h180n2fls32o849 klas]$ kwrite -v
> > > Qt: 3.2.3
> > > KDE: 3.2 BRANCH >= 20040204
> > > KWrite: 4.2
> > >
> > > It also works in a python shell...
> > >
> > >>>>os.popen("kwrite -v").readlines()
> > >
> > > ['Qt: 3.2.3\n', 'KDE: 3.2 BRANCH >= 20040204\n', 'KWrite: 4.2\n']
> > >
> > > If i try the following in a bash shell, it also workes:
> > > [klas at h180n2fls32o849 klas]$ tccat -v
> > > tccat (transcode v0.6.12) (C) 2001-2003 Thomas Oestreich
> > >
> > > But if i try the same in a python shell i get:
> > >>>>os.popen("tccat -v").readlines()
> > >
> > > []
> > >
> > > Not even if i specify the path it works.
> > >
> > >>>>os.popen("/usr/bin/tccat -v").readlines()
> > >
> > > []
> > >
> > >
> > > What am i missing?
> > >
> > > Kind Regards
> > > Klas
> > > _______________________________________________
> > > Tutor maillist  -  Tutor at python.org
> > > http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list