Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何为Azure自动输入密码?_Python_Automation_Subprocess_Passwords - Fatal编程技术网

Python 如何为Azure自动输入密码?

Python 如何为Azure自动输入密码?,python,automation,subprocess,passwords,Python,Automation,Subprocess,Passwords,我想自动登录Azure系统以访问虚拟机。我运行以下代码: process_1=subprocess.call(key.SSH_key+'|'+key.PASSKEY,shell=True)#登录到虚拟机 并收到以下文件: /bin/sh: key.PASSKEY: command not found azureuser@xx.xx.1x.1xx's password: 当它是key的输入时,它认为key.PASSKEY是另一个命令azureuser@xx.xx.1x.1xx用户密码:par

我想自动登录Azure系统以访问虚拟机。我运行以下代码:

process_1=subprocess.call(key.SSH_key+'|'+key.PASSKEY,shell=True)#登录到虚拟机
并收到以下文件:

/bin/sh: key.PASSKEY: command not found
azureuser@xx.xx.1x.1xx's password: 

当它是
key的输入时,它认为
key.PASSKEY
是另一个命令azureuser@xx.xx.1x.1xx用户密码:
part。如何确保在运行此子流程命令时自动输入
密钥.PASSKEY
作为密码?

使用以下视频找到答案:

我做到了:

    ch = pexpect.spawn(key.SSH_KEY)
    ch.logfile = sys.stdout.buffer
    ch.expect("azureuser@xx.xx.1x.1xx's password:")
    ch.sendline(key.PASSKEY)
    ch.expect("azureuser@vm")
    ch.sendline('ls')