Created
June 1, 2012 02:52
-
-
Save minrk/2848290 to your computer and use it in GitHub Desktop.
This file contains 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 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)" | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment