use lines as argument to a command
Amit Khemka
khemkaamit at gmail.com
Tue Oct 16 02:13:09 EDT 2007
On 10/16/07, Shoryuken <sakradevanamindra at gmail.com> wrote:
> > I guess that you want to loop over a file and for each line in the
> > file you want to call some
> > external program with the line as the argument.
> >
> > Have a look at subprocess module
> > http://docs.python.org/lib/module-subprocess.html
> >
> > If there is some else that you meant, please specify .
> >
> Thanks alot, its working now. But I have another question (sorry I'm
> so noob), how can I redirect a command's output to a file (just like
> executing a linux command "dmesg>>stat.txt")?
Since subprocess module allow you to call programs through (linux)
shell , you can use the same syntax in your command.
example:
>>> from subprocess import call
>>> call("echo foo >> bar.txt", shell=True)
Cheers,
--
--
Amit Khemka
More information about the Python-list
mailing list