how to interact with Windows cmd?

self.python howmuchistoday at gmail.com
Thu Jul 5 05:10:47 CEST 2012


what I want to do is
1.open cmd
2.waiting for user's typing
3.when I type "dir"
4.print the result of "dir"
5.then I type some other commands, printing the result until I type
'exit'

I used
p=subprocess.Popen('cmd',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
p=communicate('dir')

it shows the first result but the problem is
1. it's too long so the cmd split the result with "more?", so result
is not perfect
2. after this, I typed like "cd .." but I/O is already closed so I
can't do another things..

Is there any good way?



More information about the Python-list mailing list