可以使用Python中的subprocess模块来发送命令并获取设备的输出。以下是一个示例代码:

import subprocess

with open('Commands.txt', 'r') as f: commands = f.readlines()

for command in commands: command = command.strip() print('Sending command:', command) process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() print('Output:', output.decode()) print('Error:', error.decode())

使用stdin stdout stderr发送commandstrip到设备后面怎么写with openCommandstxt r as f commands = freadlines printcommandsfor command in commands printcommandstrip

原文地址: https://www.cveoy.top/t/topic/hcJy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录