触发远程运行Python脚本并在主机机器上执行它

huangapple go评论55阅读模式
英文:

Trigger a Python script remotely and run it on the host machine

问题

I have a python script which uses Tkinter library to do screen grab of the image displayed on my secondary screen. The script works perfectly fine. When I try to run the script remotely using ssh (command below)

ssh pi@testing.com "python /home/display_capture.py"

I get the following error message:

_tkinter.TclError: no display name and no $DISPLAY environment variable

which is understandable because I'm running the script from a remote machine. What's the best way to trigger the script remote but execute on the machine?

英文:

I have a python script which uses Tkinter library to do screen grab of the image displayed on my secondary screen. The script works perfectly fine. When i try to run the script remotely using ssh (command below)

ssh pi@testing.com "python /home/display_capture.py"

I get the following error message:

> _tkinter.TclError: no display name and no $DISPLAY environment variable

which is understandable because i'm running the script from a remote machine. What's the best way to trigger the script remote but execute on the machine?

答案1

得分: 3

尝试

ssh -t pi@testing.com "DISPLAY=$DISPLAY python /home/display_capture.py"

-t选项告诉ssh分配伪终端,并将DISPLAY=$DISPLAY设置为远程DISPLAY环境变量的值等于本地DISPLAY环境变量的值。

您需要在SSH服务器上启用X11转发。
英文:

Try

ssh -t pi@testing.com "DISPLAY=$DISPLAY python /home/display_capture.py"

The -t option tells ssh to allocate a pseudo-terminal, and the DISPLAY=$DISPLAY sets the remote DISPLAY environment variable to the value of the local DISPLAY environment variable.

You will need X11 forwarding enabled on the SSH server.

huangapple
  • 本文由 发表于 2023年4月6日 22:28:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950697.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定