getting from command line options to file

CSUIDL PROGRAMMEr syedamjad_a at yahoo.com
Fri Apr 20 16:48:10 EDT 2007


On Apr 16, 1:08 pm, Michael Hoffman <cam.ac... at mh391.invalid> wrote:
> CSUIDL PROGRAMMEr wrote:
> > hi folks
> > I am new to python. I have a module does call a os.command(cmd) where
> > cmd is a rpm command.
> > Instead of using os.command and getting the results on command line ,
> > i would like to dump the output in a file. Is os.command(cmd >
> > filename)  the most efficient command??
>
> I think the best thing to do would be something like this (Python 2.5):
>
> from __future__ import with_statement
> import subprocess
>
> with file("test.out", "w") as outfile:
>      subprocess.check_call(["ls", "/etc"], stdout=outfile)
> --
> Michael Hoffman


but what if i have python which  is 2.4??





More information about the Python-list mailing list