Skip to content Skip to sidebar Skip to footer

How To Get Input From User When Connecting To Remote Servers? [Python]

I need to connect to a remote server using a (non-python) script from terminal. $./myscript Normally, I would need to enter the password. I have the followin

Solution 1:

If I understand the question correctly you would probably use the getpass function.

import getpass
password = getpass.getpass()
print 'You entered:', password

The major advantage is that the password will not be visible on the screen as the user enters it.

If you simply want to pass in arguments to your application you can use sys.argv.

import sys

if len(sys.argv) > 1:
    print "First argument:", sys.argv[1]

If you need to pass on a password to a script executed by Python you can use subprocess call.

import getpass
import subprocess

password = getpass.getpass()
subprocess.call(["myscript", password ])

Post a Comment for "How To Get Input From User When Connecting To Remote Servers? [Python]"