Running python from pty without prompt

Michael Torrie torriem at gmail.com
Fri Dec 9 19:45:29 EST 2016


On 12/09/2016 04:11 PM, space.ship.traveller at gmail.com wrote:
> Hello.
> 
> I'm working on a script runner for Atom.
> 
> https://github.com/ioquatix/script-runner
> 
> We are trying to understand how to make python work well. I'll use a
> comparison to the ruby executable because it's convenient to explain
> the problem.
> 
> When you invoke `ruby` from a pty, you get no output (as opposed to
> `irb`, interactive ruby [shell]). You can write a script to stdin,
> and send Ctrl-D (EOT / 0x04). Then, ruby will execute the script.
> stdin is not closed so programs that expect interactive input will
> work correctly.
> 
> When we run python in the same way, we get an output prompt. As soon
> as a function like `input` is called, the program is interrupted.
> 
> I'm happy to hear feedback about how this should work. Perhaps our
> expectations are wrong, or what we are doing is wrong.

Not sure I understand the issue here.  You can pipe a script to Python
and it runs it without any immediate-mode prompt.  I think python only
shows the REPL prompt if you are attached to a pty.

But if the script is piped into Python or ruby, I don't know how we
could expect raw_input() or input() to function.

> One option which we've been considering is saving the input as a file
> and executing that. But, it's not as clean compared to simply writing
> a string to stdin of a running interpreter and then 0x04.

An intermediate file is unnecessary as you can pipe a script into Python.


More information about the Python-list mailing list