From b1d549aa323403a21a43b2bd4faefd417fcb2257 2010-08-16 23:12:43 From: Brian Granger Date: 2010-08-16 23:12:43 Subject: [PATCH] Initial version of system command out/err forwarding. --- diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index e206923..f3d883d 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -27,7 +27,7 @@ import zmq # Local imports. from IPython.config.configurable import Configurable -from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC +from IPython.zmq.zmqshell import ZMQInteractiveShell from IPython.external.argparse import ArgumentParser from IPython.utils.traitlets import Instance from IPython.zmq.session import Session, Message @@ -50,7 +50,7 @@ class Kernel(Configurable): def __init__(self, **kwargs): super(Kernel, self).__init__(**kwargs) - self.shell = InteractiveShell.instance() + self.shell = ZMQInteractiveShell.instance() # Build dict of handlers for message types msg_types = [ 'execute_request', 'complete_request', diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py new file mode 100644 index 0000000..681b81e --- /dev/null +++ b/IPython/zmq/zmqshell.py @@ -0,0 +1,20 @@ +import sys +from subprocess import Popen, PIPE +from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC + + +class ZMQInteractiveShell(InteractiveShell): + """A subclass of InteractiveShell for ZMQ.""" + + def system(self, cmd): + cmd = self.var_expand(cmd, depth=2) + p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + for line in p.stdout.read().split('\n'): + if len(line) > 0: + print line + for line in p.stderr.read().split('\n'): + if len(line) > 0: + print line + return p.wait() + +InteractiveShellABC.register(ZMQInteractiveShell)