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

n00m n00m at narod.ru
Fri Aug 22 23:25:49 CEST 2008


Is it possible to communicate in loop fashion?

====================================
import subprocess as s
proc = s.Popen('cmd.exe', stdin=s.PIPE, stdout=s.PIPE)
while 1:
    cmd = raw_input('cmd:')
    res = proc.communicate(cmd + '\n')[0]
    print res
====================================
cmd:dir c:
< res >

cmd:dir d:

Traceback (most recent call last):
  File "D:\Python25\my_subprocess.pipe.py", line 11, in <module>
    res = proc.communicate(cmd + '\n')[0]
  File "D:\Python25\lib\subprocess.py", line 651, in communicate
    return self._communicate(input)
  File "D:\Python25\lib\subprocess.py", line 862, in _communicate
    self.stdin.write(input)
ValueError: I/O operation on closed file




More information about the Python-list mailing list