简体   繁体   English

如何在Windows PC上使用python脚本在Unix上截屏?

[英]How do I take screenshot on Unix using python script on windows PC?

Am trying to take a screenshot of UNIX server from my Windows PC. 我正在尝试从Windows PC截取UNIX服务器的屏幕截图。 My command is not working it seems. 我的命令似乎无效。 When I try the same command on terminal it saves the file, however it is not with my below code. 当我在终端上尝试相同的命令时,它会保存文件,但是下面的代码却没有。

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(sftp_server, username=sftp_login, password=sftp_password)
stdin, stdout, stderr = ssh.exec_command("xwd -root | convert xwd:- screenshot22.jpg")

sftp = ssh.open_sftp()
transport = paramiko.Transport((sftp_server, sftp_port))
transport.connect(username = sftp_login, password = sftp_password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.get("screenshot22.jpg", 'screenshot22.jpg', None)

sftp.close()
ssh.close()

Note: 1. xwd is installed on my UNIX Server. 注意:1. xwd已安装在我的UNIX服务器上。 2. Tried Import command, but that takes (2nd desktop of UNIX, not the one am trying to) 2.尝试了导入命令,但是需要(UNIX的第二个桌面,而不是我尝试的一个)

With the help of @Christopher Apple, I have figured out a way. 在@Christopher Apple的帮助下,我找到了一种方法。

The working source code is, 有效的源代码是,

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(sftp_server, username=sftp_login, password=sftp_password)
stdin, stdout, stderr = ssh.exec_command("xwd -out screenshot.xwd -root -display :0.0")
stdin, stdout, stderr = ssh.exec_command("convert screenshot.xwd screenshot22.jpg")

sftp = ssh.open_sftp()
transport = paramiko.Transport((sftp_server, sftp_port))
transport.connect(username = sftp_login, password = sftp_password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.get("screenshot22.jpg", 'screenshot22.jpg', None)
sftp.close()
ssh.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM