[英]How i can use variable present in python program inside the execute command function of linux
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect('example.com',22,'XXXXX','XXXX')
a=input ("enter the file path")
stdin,stdout,stderr=client.exec_command('cd a && pwd')
I want to pass the variable 'a' to the exec_command .. I am trying to get the file path from the user and i am storing it in a variable a, i want to know how i can pass the variable a to the Cd command under exec_command function 我想将变量“ a”传递给exec_command ..我正试图从用户那里获取文件路径,并将其存储在变量a中,我想知道如何将变量a传递给Cd命令。在exec_command函数下
Since there can be some security flaws by code injection, you must not format user input directly into shell commands. 由于代码注入可能会带来一些安全漏洞,因此您不能直接将用户输入格式化为shell命令。
Here you can use environment variables: 在这里您可以使用环境变量:
stdin,stdout,stderr=client.exec_command('cd "$a" && pwd', environment={'a': a})
您是否尝试根据变量构造命令?
stdin,stdout,stderr=client.exec_command('cd ' + str(a) + '&& pwd')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.