2

I am writing a SSH command line wrapper but I discovered that doesn't want to run interactively.

Let's say I do have ssh.py which is supposed to establish an interactive ssh session.

If I run:

  • subprocess.open('ssh -t server') and p.wait(), I will get an error: Pseudo-terminal will not be allocated because stdin is not a terminal.
  • if I try to force it by using -t -t it will block.

Note: I really need an interactive session, as I try to use screen to restore a previous connection.

How can I solve this problem?

Note: I do not want to control the called ssh from python in any way.

sorin
  • 161,544
  • 178
  • 535
  • 806
  • 1
    Have you seen the answers to this related question: http://stackoverflow.com/questions/4664002/pseudo-terminal-will-not-be-allocated-because-stdin-is-not-a-terminal-when-run – jedwards May 21 '12 at 23:08
  • @jedwards now I did, still the other one doesn't provide an answer to the problem. – sorin May 21 '12 at 23:26
  • Should I reimplement my wrapper in `bash`? I do not have the same problem if I call `bash`. Still, I would prefer to use python, because doing the same logic in bash would be... really ugly. – sorin May 21 '12 at 23:35
  • What exactly do you mean by "I do not want to control the called ssh from Python in any way"? Is it ok to spawn ssh with your underlying OS, but look at ssh's prompts in python? – Mike Pennington May 22 '12 at 10:11
  • So you basically want a terminal emulator for Python? – plaes May 22 '12 at 10:24

1 Answers1

0

You might want to look into Fabric instead.

plaes
  • 31,788
  • 11
  • 91
  • 89
  • Thanks, but in this case I am looking for a one-file solution so using external libraries. In fact the question should have nothing to do with SSH, it should also apply for the case you want to run an interactive console application locally too. – sorin May 22 '12 at 10:19