【发布时间】:2018-11-14 10:30:06
【问题描述】:
我正在尝试在 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 并连接到此窗口的 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 机器无法远程打开这个应用程序
有什么想法可以解决这个问题吗?
【问题讨论】:
-
所以
rtmserver的路径在您本地Windows 帐户的PATH环境变量中? -
您是否使用与在 Windows 上本地使用的帐户相同的帐户登录 SSH?
-
您可能需要指定
rtmserver.bat脚本的完全限定路径。如果这还不够,可能需要使用cmd.exe /C "C:\Program Files (x86)\Video Clarity\RTMonitor>rtmserver" 7 5。 -
为什么不直接执行 rtmserver 而不是放到批处理文件中呢?
-
@Squashman,怎么样?
标签: linux windows batch-file cmd paramiko