OS specific command in Python

stephanearnold at yahoo.fr stephanearnold at yahoo.fr
Tue Jun 20 02:02:04 EDT 2006


diffuser78 at gmail.com a écrit :

> So basically, instead of typing in on the command line argument I want
> to have it in a python program and let it do the action.

Try exec() and execfile() from the standard library (IIRC)

>
> for example. in my program I would want to call the ssh feature like
> one does on the command line
>
> ssh Admin at 192.168.2.10          .....etc
>

When you connect (via ssh or telnet) to a remote machine, you need to
type (manually)
your username and your password. Programming that is never easy.

If what you need is simulating console interaction, you will need to
get Expect.
Expect allows you to program/emulate user interaction in a text
console, based on the Tool Command Language (a.k.a. Tcl).

But there are alternatives : start a SSH daemon written as a shell
script. (you just have to enter your login/pass once, then call the
daemon to execute some commands)

IMHO, Expect is by far the cleanest way.

Regards,
Stéphane




More information about the Python-list mailing list