Created
October 22, 2019 20:36
-
-
Save maedoc/c20a9125af0a9b23656f5beb65e1c97b to your computer and use it in GitHub Desktop.
SSH cell magic for IPython/Jupyter
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
import IPython.core.magic, subprocess | |
@IPython.core.magic.register_cell_magic | |
def ssh(line, cell): | |
proc = subprocess.Popen(['ssh'] + line.split(), | |
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
out, _ = proc.communicate(cell.encode('ascii')) | |
print(out.decode('ascii')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment