redirect or cover .bat log

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Aug 22 10:01:49 EDT 2007


On 22 ago, 10:04, vedrandeko... at v-programs.com wrote:
>
> > >> > e.g I need run my my_scripts_setup.bat that contain:
>
> > >> > python myscript_setup.py py2exe
>
> > >> > Can I cover or redirect log of that process into my wx program?
> > >> > I'am using Windows XP SP2, and Python 2.5.

Try the subprocess module. For the single line command you posted
earlier, you don't even need the bat file:

import subprocess
p = subprocess.Popen(["python", "myscript_setup.py", "py2exe"],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
output_from_process = p.stdout.readlines()

This would be fine if executing the script takes relatively a short
time and doesn't generate so many output lines; there are other
examples in the subprocess module documentation <http://
docs.python.org/lib/module-subprocess.html>

--
Gabriel Genellina




More information about the Python-list mailing list