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

n00m n00m at
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\", line 11, in <module>
    res = proc.communicate(cmd + '\n')[0]
  File "D:\Python25\lib\", line 651, in communicate
    return self._communicate(input)
  File "D:\Python25\lib\", line 862, in _communicate
ValueError: I/O operation on closed file

More information about the Python-list mailing list