Re: Calling multiple programs with subprocess

2010-04-23 Thread Amit Uttamchandani
On Thu, Apr 22, 2010 at 10:12:47PM -0400, Dave Angel wrote:
> amit wrote:
> >How does one go about calling multiple programs using subprocess?
> >
> >This is the program flow:
> >
> >C:\> wrenv.exe
> >C:\> make clean
> >..
> >..
> >
> >The 'wrenv.exe' is necessary since it sets up the proper environment
> >for building. How do I use subprocess to execute 'wrenv.exe' and then
> >the 'make clean' command.
> >
> >Any help is appreciated.
> >
> >Thanks,
> >Amit
> >
> One way is to write a batch file (since you're on Windows), and
> execute that with shell=True.
> 
> It's not the only way, or the most efficient.  But it's most likely
> to work, without knowing anything more about those two programs.
> 
> DaveA
> 

Thanks Dave.

That's actually a good idea and in this case probably the only way that
this would work. I can auto-generate the batch file from the python
script with the parameters that I need and just execute that with the
subprocess.

I wish there was a cleaner was as well.

But thanks for tip!

Amit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [SOLVED] Calling multiple programs with subprocess

2010-04-30 Thread Amit Uttamchandani
On Sat, Apr 24, 2010 at 08:22:14AM +0530, Kushal Kumaran wrote:

[snip]

>
> Run a shell (cmd.exe, I think) using subprocess and send it the
> commands you want to run using the communicate() method.
> 

Actually, I ended up using stdin.write('...\n'), and it works as expected:

#
# Set WindRiver environment for VxWorks 6.4
#
wrenv_path = "C:\WindRiver\wrenv.EXE"
args = [wrenv_path, '-p', 'vxworks-6.4']
proc = subprocess.Popen(args,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE
   )
proc.stdin.write(str.encode('wrws_update -data %s -l %s -b clean\n' %
   (workspace, self.target)))
output, error = proc.communicate()
print(output)
print(error)

You can keep using stdin.write until you call communicate() this allows
you to write certain commands to the stdin for the process you launched.
Note: wrenv.exe is actually a shell like cmd.exe.

The above code is written for Python 3.1.

Thanks for the help.
-- 
http://mail.python.org/mailman/listinfo/python-list