我正在使用paramiko在远程windows服务器上执行命令。我能够执行dir之类的命令并提取输出,但是执行python脚本似乎失败了。不会引发错误消息。在
下面是我的代码片段:def ssh_connect(ip,user,pwd):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=user, password=pwd)
return ssh
def execute_command(device_details, command):
ip = device_details.get('ip')
username = device_details.get('username')
password = device_details.get('password')
ssh_ns_obj = ssh_connect(ip, username, password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh_ns_obj.exec_command(command)
print ssh_stderr.read()
return ssh_stdout.read()
device_details = dict()
device_details['ip'] = 'a.b.c.d'
device_details['username'] = 'Administrator'
device_details['password'] = 'pass'
command_1 = "cmd /c mkdir asdf"
output = execute_command(device_details, command_1)
command_2 = 'cmd /c "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe C:\pythonattempt\try.py"'
output = execute_command(device_details, command_2)
以下是我在command_2中提到的try.py:
^{pr2}$
command_1执行成功,我可以看到在我的windows机器上创建的目录。但是command_2不会抛出任何错误,但也不会被执行。在
我知道是因为x.txt或文件夹x没有创建。在
我已经在Windows上安装了freeSSHd服务。我能够ssh进入我的Windows机器,执行完全相同的命令,它正在工作。在
见下图:
我该怎么做?在