你能帮我解决这个问题吗?
AdminServer = "putty.exe -ssh 1.1.1.1"
Server1 = "putty.exe -ssh 2.2.2.2"
Server = requests.get('example.com')
#this returns the server name (AdminServer or Server1...)
subprocess.Popen(Server)
当我运行这个时,我得到:
WindowsError: [Error 2] The system cannot find the file specified
可能是因为subprocess.Popen
尝试打开命令AdminServer
(不是命令)而不是它的值 ( putty.exe -ssh 1.1.1.1
)
任何帮助表示赞赏。谢谢
使用字典,而不是变量。如果您有变量名称,则获取变量内容的方法是evil
,而且几乎总是有更好的方法。在这种情况下:
server_connection_commands = {
"AdminServer": "putty.exe -ssh 1.1.1.1",
"Server1": "putty.exe -ssh 2.2.2.2"
}
server = requests.get('http://example.com').text
subprocess.Popen(server_connection_commands[server])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句