英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论