你可以将以上代码转换为如下形式来传递参数:
import paramiko
import time
# 定义要执行的命令和参数
order = 'python3 $pyScript -b $binaryFiles -e -s $COM -k $burnVersion -i $IPAddr --boot-fw $boot --active-fw $production_test --passive-fw $app --customer-config $customer --production-data $json'
order = order.replace('$pyScript', pyScript)
order = order.replace('$binaryFiles', binaryFiles)
order = order.replace('$COM', BURN_COM)
order = order.replace('$burnVersion', BURN_VERSION)
order = order.replace('$IPAddr', BURN_IP)
order = order.replace('$boot', BURN_BOOT_PATH)
order = order.replace('$production_test', BURN_PRODUCTION_TEST_PATH)
order = order.replace('$app', BURN_APP_PATH)
order = order.replace('$customer', BURN_CUSTOMER_CONFIG_PATH)
order = order.replace('$json', BURN_BUILD_PATH)
try:
ssh = paramiko.SSHClient()
# 连接SSH服务器,具体参数根据实际情况进行设置
ssh.connect(hostname=hostname, username=username, password=password)
channel = ssh.invoke_shell()
channel.send(order + '\n')
Status = 0
while Status < 2:
time.sleep(0.1)
stdout = channel.recv(1024)
print(stdout.decode().replace('\r', ''))
if "Burn M1908" in stdout.decode():
Status += 1
except Exception as e:
print('Fail to carry out command:', str(e))
finally:
if ssh is not None:
ssh.close()
注意,你需要根据实际情况修改 hostname
、username
和 password
,并确保你的代码中包含了对paramiko库的导入语句。另外,这里假设你已经定义了变量 pyScript
、binaryFiles
等,用于替换命令中的占位符。
内容由零声教学AI助手提供,问题来源于学员提问