Re: Inheriting a command line - or how to efficiently replace Unix' os.execvpe

"Sebastian M. Ernst" <[email protected]>
Newsgroups gmane.comp.python.windows
Message-ID <[email protected]>
Hi Eryk,

thanks a lot for the explanation. It's amazing how Windows does things
differently in so many places ...

> The grandparent and its grandchild will then compete with each other
> for console I/O, which is an interleaved mess. You'll get a prompt
> from the grandparent, but the text you enter will be read by the
> grandchild. Then you'll get the grandchild's prompt, and so on.

Yes, this is exactly what I have been observing so far.

> If you want to reuse the current console session, you'll have to spawn
> ssh, wait for it to exit, and proxy its exit status. That's the
> closest you can get to using exec*() in a POSIX system.

Yes, ideally I'd want to reuse the current console session, but I am
failing at disentangling the "interleaved mess".

> A console session doesn't implement the POSIX concept of foreground
> and background process groups. Any process that's attached to a
> console can read and write from it. Generally when one starts a child
> process in the same console session, one either avoids using console
> I/O until the child exits, or one simply blocks and does nothing while
> waiting for the child to exit. Typically a command-line shell (e.g.
> cmd.exe) implements the latter.

If my Python process was "simply idling" / blocking, `ssh` could do its
thing (fully interactively) in the meantime. Do I understand you
correctly that this can actually be done?

I have done a few dumb experiments along the lines of ...

```python
proc = subprocess.Popen(['ssh', 'user@host'], **parameters)
while proc.poll is None:
    time.sleep(0.25)
```

... but I am not managing to specify `parameters` so that I can actually
interact with `ssh`. Am I on the wrong track ... ?

Best regards,
Sebastian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.