Search code examples
pythonpexpect

How can I pass a string to pexpect spawn?


I want to ssh to another node on my network as part of a larger python script, I am using pexpect which works when I do something like this:

session=spawn('ssh [email protected]')

I want to replace the address with a variable so I can cycle through addresses in a list however when I try:

address = "172.16.210.253"

session=spawn('ssh root@'address)

It doesn't work as using address in this way is invalid syntax. What is the correct syntax for this?


Solution

  • session=spawn('ssh root@' + address) to concatenate the strings