Created
March 3, 2014 08:20
-
-
Save saghul/9320662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -u | |
import signal | |
import sys | |
import pyuv | |
pyuv.Process.disable_stdio_inheritance() | |
def on_signal(handle, signum): | |
sys.exit() | |
def on_source_read_stdin(handle, data, error): | |
if data is None: | |
source_stdin.close() | |
source_stdout.close() | |
source_stderr.close() | |
else: | |
dest_stdin.write(data) | |
def on_dest_read_stdout(handle, data, error): | |
if data is None: | |
dest_stdin.close() | |
dest_stdout.close() | |
dest_stderr.close() | |
else: | |
source_stdout.write(data) | |
def on_dest_read_stderr(handle, data, error): | |
if data is None: | |
dest_stdin.close() | |
dest_stdout.close() | |
dest_stderr.close() | |
else: | |
source_stderr.write(data) | |
def on_child(handle, status, signum): | |
sys.exit() | |
loop = pyuv.Loop.default_loop() | |
signal_h = pyuv.Signal(loop) | |
signal_h.start(on_signal, signal.SIGINT) | |
source_stdin = pyuv.TTY(loop, sys.stdin.fileno(), True) | |
source_stdout = pyuv.TTY(loop, sys.stdout.fileno(), False) | |
source_stderr = pyuv.TTY(loop, sys.stderr.fileno(), False) | |
#source_stdin = pyuv.Pipe(loop) | |
#source_stdin.open(sys.stdin.fileno()) | |
#source_stdout = pyuv.Pipe(loop) | |
#source_stdout.open(sys.stdout.fileno()) | |
#source_stderr = pyuv.Pipe(loop) | |
#source_stderr.open(sys.stderr.fileno()) | |
dest_stdin = pyuv.Pipe(loop) | |
dest_stdout = pyuv.Pipe(loop) | |
dest_stderr = pyuv.Pipe(loop) | |
child_stdio = [] | |
child_stdio.append(pyuv.StdIO(stream = dest_stdin, flags = pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE)) | |
child_stdio.append(pyuv.StdIO(stream = dest_stdout, flags = pyuv.UV_CREATE_PIPE | pyuv.UV_READABLE_PIPE)) | |
child_stdio.append(pyuv.StdIO(stream = dest_stderr, flags = pyuv.UV_CREATE_PIPE | pyuv.UV_READABLE_PIPE)) | |
child = pyuv.Process(loop) | |
child.spawn(file = "/usr/bin/ssh", | |
#args = ["-T", "localhost"], | |
args = ["-tt", "localhost"], | |
stdio = child_stdio, | |
exit_callback = on_child) | |
source_stdin.start_read(on_source_read_stdin) | |
dest_stdout.start_read(on_dest_read_stdout) | |
dest_stderr.start_read(on_dest_read_stderr) | |
loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment