I am trying to pass a bash shell to / from a simple WebSockets user interface, but I am having problems with IO redirection. I want to start a bash instance and connect the stdout and stdin functions to write_message () and on_message (), which interact with my web interface. Here is a simplified version of what I'm trying to do:
class Handler(WebSocketHandler): def open(self): print "New connection opened." self.app = subprocess.Popen(["/bin/bash", "--norc", "-i"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False) thread.start_new_thread(self.io_loop, ()) def on_message(self, message): self.app.stdin.write(message) def on_close(self): self.app.terminate() def io_loop(self): while self.app.poll() is None: line = self.app.stdout.readline() if line: self.write_message(line)
While bash is starting and on_message is calling, I am not getting any output. readline () remains a lock. I tried stdout.read (), stdout.read (1) and various buffer modifications, but still do not output. I also tried hardcoding commands with a trailing "\ n" in on_message to isolate the problem, but I still don't get any output from readline ().
Ideally, I want to transfer every byte written to stdout in real time, without waiting for EOL or other characters, but it's hard for me to find the right API. Any pointers would be appreciated.
source share