From b8470d6a80176543e05ae8ca4b4945c155116901 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Mon, 15 Dec 2008 19:33:05 +0000 Subject: [PATCH] """echo "print 'test'" | bpython""" no longer breaks bpython now checks if stdin is a tty and, if not, executes stdin through a simple interpreter instance and exits. --- CHANGELOG | 3 +++ bpython/cli.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 042f406..e77e003 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,9 @@ Menno sent me some patches to fix some stuff: flush_output option added to config to control whether output is flushed to stdout or not on exit. +Piping something to bpython made it lock up as stdin was not the keyboard - +bpython just executes stdin and exits instead of trying to do something clever. + v0.7.1 ====== Added support for a history file, defaults to ~/.pythonhist and 100 lines but diff --git a/bpython/cli.py b/bpython/cli.py index 5ef803b..e243815 100644 --- a/bpython/cli.py +++ b/bpython/cli.py @@ -45,7 +45,7 @@ import string import shlex import socket import pydoc -import cStringIO +from cStringIO import StringIO # These are used for syntax hilighting. from pygments import highlight @@ -1715,7 +1715,13 @@ def main_curses(scr): def main(): + if not os.isatty(sys.stdin.fileno()): + interpreter = code.InteractiveInterpreter() + interpreter.runsource(sys.stdin.read()) + return + tb = None + try: o = curses.wrapper(main_curses) except: