Jump to content

Trying to mimic a remote shell

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
codeLoad

codeLoad

    Newbie

  • Members
  • PipPip
  • 16 posts
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:

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

The problem is, the call to read() does not return. Anyone know a way to do this?

#2
deskchecked

deskchecked

    Newbie

  • Members
  • PipPip
  • 29 posts
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.