how to get output.

indu_shreenath at yahoo.co.in indu_shreenath at yahoo.co.in
Fri Aug 10 05:00:28 EDT 2007


On Aug 10, 12:02 am, Larry Bates <larry.ba... at websafe.com> wrote:
> indu_shreen... at yahoo.co.in wrote:
> > I corrected a typ below.
>
> > On Aug 9, 12:50 pm, indu_shreen... at yahoo.co.in wrote:
> >> Hey,
>
> >> I did write the following:
> >> but it does not work.
>
> >> import subprocess as sp
> >> try:
> >>     p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
> >>     result = p.communicate()[0]
> >>     print result
> >>  except:
> >>      print "error"
>
> >> This throws error.
> >> DIR . /AD /B will list out only directories in the current directory.
>
> >> Thanks,
> >> Indu
>
> >> On Aug 9, 11:46 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>
> >>> indu_shreenath schrieb:
> >>>> Hey,
> >>>> I want to get the output of "DIR /AD /B" command to a varriable using
> >>>> python. How can I do this?
> >>> Using the subprocess-module.
> >>> However, I'm not sure what DIR /AD /B does - but there are many
> >>> functions in module os that might deliver what you want without invoking
> >>> an external command.
> >>> Diez- Hide quoted text -
> >> - Show quoted text -
>
> That is better done in python with:
>
> import os
> dirs=[d for d in os.listdir(os.curdir) if os.path.isdir(d)]
>
> or
>
> dirs=filter(os.path.isdir, os.listdir(os.curdir))
>
> -Larry- Hide quoted text -
>
> - Show quoted text -

Thanks I could implement it.

Indu






More information about the Python-list mailing list