Interactive sub process

283 views
Skip to first unread message

Rajdeep Rath

unread,
Oct 11, 2020, 2:21:49 AM10/11/20
to python-...@googlegroups.com
Hello,

Is there any way to make the sub process interactive? Currently if I runs. She’ll command using subprocess and the command requires input in between the sub process exits. How can we make it such that it can wait there till I write something to the sub process input stream ? 

Is this possible or will this be possible in future versions ?

Rajdeep Rath

unread,
Oct 11, 2020, 4:22:11 AM10/11/20
to python-...@googlegroups.com
Hello,

Is there any way to make the sub process interactive? Currently if I run a Shell command using subprocess and the command requires input in between the sub process exits. How can we make it such that it can wait there till I write something to the sub process input stream ? 

Is this possible or will this be possible in future versions ?
(Typos corrected)

Ben Darnell

unread,
Oct 11, 2020, 10:26:40 AM10/11/20
to Tornado Mailing List
Yes, you can interact with the subprocess by assigning both `stdin` and `stdout` to `Subprocess.STREAM` and using methods like `subproc.stdout.read_until` and `subproc.stdin.write`. Here's an example from the Tornado test suite: https://github.com/tornadoweb/tornado/blob/5913aa43ecfdaa76876fc57867062227b907b1dd/tornado/test/process_test.py#L153-L170

Sometimes you need to pass command-line flags to the subprocess to tell it to be interactive even though it doesn't look like it's being run in a regular terminal. For example, when running `python` as in the above example, you must pass both `-u` (unbuffered output) and `-i` (interactive mode).

This assumes a shell-like process that reads its input in the usual way. It's not compatible with full-screen terminal apps like emacs or vim, and sometimes it doesn't work with apps that try to do something special for password input. For that you'd need something that can create a pseudo-terminal (I don't have any experience with this, but `tty` and `pty` are good keywords to search for)

-Ben

On Sun, Oct 11, 2020 at 4:22 AM Rajdeep Rath <rajde...@gmail.com> wrote:
Hello,

Is there any way to make the sub process interactive? Currently if I run a Shell command using subprocess and the command requires input in between the sub process exits. How can we make it such that it can wait there till I write something to the sub process input stream ? 

Is this possible or will this be possible in future versions ?
(Typos corrected)

On Sun, 11 Oct, 2020, 11:51 am Rajdeep Rath, <rajde...@gmail.com> wrote:
Hello,

Is there any way to make the sub process interactive? Currently if I runs. She’ll command using subprocess and the command requires input in between the sub process exits. How can we make it such that it can wait there till I write something to the sub process input stream ? 

Is this possible or will this be possible in future versions ?

--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-tornado/CAP869y9%2BupfMvaZ8Q%2BrahKKTzpFb-Tf9qDq5NKWF%2Baay9Uhu2g%40mail.gmail.com.

Rajdeep Rath

unread,
Oct 11, 2020, 10:56:37 AM10/11/20
to python-...@googlegroups.com
Thank you for the response Mr Darnell. I will try it out and let you know how it goes. ..and as usual thank you for your work on this.😀

Reply all
Reply to author
Forward
0 new messages