Skip to content

Instantly share code, notes, and snippets.

@maedoc
Created October 22, 2019 20:36
Show Gist options
  • Save maedoc/c20a9125af0a9b23656f5beb65e1c97b to your computer and use it in GitHub Desktop.
Save maedoc/c20a9125af0a9b23656f5beb65e1c97b to your computer and use it in GitHub Desktop.
SSH cell magic for IPython/Jupyter
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