public
Created

  • Download Gist
shebang.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import sys
import shlex
from subprocess import Popen, PIPE
from IPython.utils.py3compat import unicode_to_str
 
def shebang(line, cell):
cmd = shlex.split(unicode_to_str(line))
p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
out,err = p.communicate(cell)
if err:
print >> sys.stderr, err
print out
get_ipython().register_magic_function(shebang, 'cell')
 
"""
From now, you can do:
 
%%shebang bash
uname -a
echo "foo $(hostname)"
 
"""

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.