Newbie question about sending and receiving data to the command prompt.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Aug 20 02:46:14 EDT 2008


En Tue, 19 Aug 2008 16:48:26 -0300, aditya shukla  
<adityashukla1983 at gmail.com> escribi�:

> I am using windows vista and i am trying to send data to the command  
> prompt
> ,this is what is done.
>
> import subprocess
> proc =subprocess.Popen('cmd.exe',stdin=subprocess.PIPE)
> proc.communicate('abc')
> when i run this the command prompt just blinks and disappears , can  
> anyone
> explain what's going on?

I don't have a Vista machine to test right now, but I'd expect the above  
sequence to hang indefinitely. If you want to execute something, don't  
forget the final \n
On XP this works fine:

import subprocess
proc  
=subprocess.Popen('cmd.exe',stdin=subprocess.PIPE,stdout=subprocess.PIPE)
output = proc.communicate('dir\n')[0]
print repr(output)

-- 
Gabriel Genellina




More information about the Python-list mailing list