Running python from pty without prompt

Steve D'Aprano steve+python at pearwood.info
Tue Dec 13 19:10:40 EST 2016


On Wed, 14 Dec 2016 09:24 am, Random832 wrote:

> On Tue, Dec 13, 2016, at 17:09, Michael Torrie wrote:
>> On 12/13/2016 10:48 AM, Random832 wrote:
>> > The problem is there's currently no way to differentiate "interactive
>> > mode" from "script run on a tty".
>> > 
>> > You can get similar behavior with python -c "import
>> > sys;exec(sys.stdin.read())"
>> 
>> Are you sure? I can pipe scripts into Python and they run fine and
>> Python is not in interactive mode.
> 
> Yes, a pipe and a tty are two different things.


Can you show a simple demonstration of what you are doing?

I'm having difficulty following this thread because I don't know
what "script run on a tty" means.

I thought that with the exception of scripts run from cron, any time you run
a script *or* in interactive mode, there is an associated tty. Am I wrong?



>> python < script.py
>> 
>> The behavior the OP is looking for of course is a way of demarcating the
>> end of the script and the beginning of data to feed the script.
> 
> It's more than just that - with a tty you can call sys.stdin.read()
> multiple times, and each time end it with ctrl-d.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.



More information about the Python-list mailing list