[英]Run python script function in remote machine
我在远程设备中有脚本,我想在远程设备中的python脚本中运行特定功能
远程设备具有以下脚本:
#connect.py
class ConnectDevice:
def __init__(self, ip):
connect.Device(ip)
def get_devicestate(self):
state = show.Device_State
return state
函数get_devicestate返回上或下。
如何从源计算机获取get_devicestate输出。 源计算机具有以下脚本:
import os
import sys
import time
import getpass
import errno
import json
import subprocess
import threading
from subprocess import call
from subprocess import check_output
call(["ssh", "1.1.1.1", "\"python Connect.py\""])#This is just example how to run script from source to remote. Need help how to run function get_devicestate and get value.
乍看之下,似乎connect.py拥有比您粘贴在问题中更多的代码。 无论如何,假设connect.py不需要运行任何输入参数,只需使用子进程的check_output方法获取stdout消息并将其存储在变量中以备将来使用。
from subprocess import check_output
out = check_output(["ssh", "1.1.1.1", "\"python Connect.py\""])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.