I am writing a simple secure shell type program (its not encrypted though) for windows and am having an issue feeding input to a process. I used the following code:
The problem is, the call to read() does not return. Anyone know a way to do this?Code:from subprocess import Popen, PIPE import sys p = Popen('netsh',shell=False,stdout=PIPE, stderr=PIPE, stdin=PIPE) while(True): m = raw_input(">") out = None try: p.stdin.write(m) out = p.stdout.read() except: print sys.exc_info() print p.returncode print out
Unfortunately, read() will block until data is available. The python docs may also have an option for performing non-blocking reads, but I don't know whether such support exists outside of sockets. If that's not an option, you'll probably need to use a separate thread for reads.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks