views:

93

answers:

3

I tried

echo "print 'hello'" | ipython

Which runs the command but ipython immediately exits afterwards.

Any ideas? Thanks!

Edit: I actually need to pass the command into the interactive Django shell, e.g.:

echo "print 'hello'" | python manage.py shell

so the -i switch gimel suggested doesn't seem to work (the shell still exits after execution)

A: 

I'm not sure of ipython but the basic python interpreter has a command line parameter to give you the prompt after it executes the file you've given it. I don't have an interpreter handy to tell you what it is but you can get it using python --help. It should do exactly what you want.

Noufal Ibrahim
+3  A: 

Use the same flag used by the standard interpreter, -i.

-i

When a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command, even when sys.stdin does not appear to be a terminal. The PYTHONSTARTUP file is not read.

A Linux example, using the -c command line flag:

$ ipython -i -c 'print "hello, ipython!"'
hello, ipython!

In [2]: print "right here"
right here

In [3]:
gimel
Right! That's the one.
Noufal Ibrahim
well, I cheated a bit, my actual python command is already "python manage.py shell", for starting the interactive Django shell. So I can't see how the -i solution works for me.
Gj