linux - 使用 Python 从 Linux 执行窗口应用程序

标签 linux windows batch-file cmd paramiko

我正在尝试在 Windows 服务器上运行批处理文件。该批处理文件包含以下代码: “rtmserver 7 5”。

实际上在 Windows 上运行:

C:\Program Files (x86)\Video Clarity\RTMonitor>rtmserver 7 5

即,它打开 cmd 并运行此命令以正确启动 Windows 应用程序

以同样的方式: 如果我双击批处理文件,它会打开这个软件,我可以使用它。 我将其拖放到 cmd 中,它也可以运行(C:\Users\user>C:\Users\user\Desktop\ClarityCommands\RTMServer.bat.lnk)

但是,如果我尝试从在使用 paramiko 并连接到此 Windows 的其他 Linux 计算机上运行的 SSH 连接打开它,则会失败:

class SSH_Connection(object):
    def __init__(self, LOCAL_IP, username, password):
        self.LOCAL_IP = LOCAL_IP
        self.username = username
        self.password = password
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.client.connect(self.LOCAL_IP, username=self.username, password=self.password)
        self.sftp = self.client.open_sftp()
    def std(self, message):
        self.message = message
        _in, out, err = self.client.exec_command(self.message)
        exitcode = out.channel.recv_exit_status()
        stdout = ''.join(out.read())
        stderr = ''.join(err.read())
        return stdout, stderr, exitcode

class Clarity(SSH_Connection):
     pass

clarity = Clarity(LOCAL_IP='172.24.11.57', username='user', password='user')

现在,当我尝试调用批处理文件以通过 Python 给出的以下 paramiko 和 SFTP 选项执行此应用程序的打开时:

clarity.std('"C:\Program Files (x86)\Video Clarity\RTMonitor\RTMServer.bat"')

这将返回以下内容:

('\r\nuser@CV-S2042-RTM C:\\Users\\user>rtmserver 7 5 \r\n',
 "'rtmserver' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n",
 1)

所以,我的 Linux 机器无法远程打开这个应用程序

有什么想法可以解决这个问题吗?

最佳答案

所以,看看你的输出:

('\r\nuser@CV-S2042-RTM C:\Users\user>rtmserver 7 5 \r\n', "'rtmserver' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n", 1)

这表明您正在尝试从 C:\Users\user 运行 rtmserver

除非 PATH 环境变量中存在 rtmserver 的路径,系统将假定可执行文件位于当前工作目录(即 C:\Users\user)

C:\Program Files (x86)\Video Clarity\RTMonitor 添加到 PATH 环境变量应该可以解决此问题。

关于linux - 使用 Python 从 Linux 执行窗口应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53298036/

相关文章:

c - KILL 信号是否立即退出进程?

Windows批处理文件,等待命令完成?

c# - 从 C# 在同一环境中执行多个命令

windows - 如何将脚本的输出复制到 Windows 剪贴板?

batch-file - 使用 robocopy 截断日志

linux - 如何在 wget 中的主机名内跟踪重定向?

linux - 如何读取头文件 block gcc 编译器放入 .o .a 和可执行文件

c - 为 ARM 交叉编译时 header 子目录错误

c++ - 基于 Qt 的 UI 是否足够可靠以用于医疗设备?

windows - 如何撤消 Windows 上的最后一个 cd 命令?