【问题标题】:Open an lxterminal window via shell script triggered by udev rule通过 udev 规则触发的 shell 脚本打开 lxterminal 窗口
【发布时间】:2016-08-18 03:56:22
【问题描述】:

我正在尝试通过 UDEV 规则触发的 shell 脚本启动一个 等待用户输入的 python 脚本 。输入到达后,python 脚本需要进行一些数据库调用。我遇到了几个不同的问题。

这里是 udev 规则:

SUBSYSTEM=="usb" RUN+="/path/to/script.sh"

问题 #1 - 我似乎无法让它真正打开窗口。这是我在 script.sh 中的内容:

#!/bin/bash
lxterminal -e /path/to/python_script.py

这是我从 udev 得到的错误:

'/path/to/script.sh'(err) '(lxterminal:4606): Gtk-WARNING **: cannot open display: '

这是另一个版本的 shell 脚本,它实际运行,但不可见,并在检查输入时崩溃。猜测是因为如果我打开终端,我需要重新路由标准输入?脚本:

export DISPLAY=0:; bash -c /path/to/script.sh

错误:

(err) name = input('Enter your name')
(err) 'EOFError: EOF when reading a line'

如果我去掉输入,我会得到这个错误:

[4859] exit with return code 0

这个答案听起来像是不可能的,但这是编程任何应该是可能的! https://unix.stackexchange.com/questions/119078/cannot-run-script-using-udev-rules

这个论坛的结束听起来是可能的,但我需要使用 Zenity 吗? https://ubuntuforums.org/showthread.php?t=759389

任何来自更熟悉 udev 的人的信息都会很棒!

【问题讨论】:

    标签: linux shell terminal rule udev


    【解决方案1】:

    对于问题 #1;

    lxterminal --command "python -i /path/to/python_script.py"
    

    【讨论】:

    • 感谢您的建议 - 不幸的是会导致相同的显示警告:(
    【解决方案2】:

    我在这里找到了我需要的信息:Scripts launched from udev do not have DISPLAY access anymore?

    udev调用的脚本:

    export DISPLAY=:0.0; export XAUTHORITY='/var/run/lightdm/root/:0'; /path/to/python.py
    

    然后在我的 python.py 脚本中:

    cmd = ["zenity", "--entry", "--title='title'", "--text='{}'".format(var)]
    response = (subprocess.check_output(cmd)).decode("utf-8") # Decode to a string
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      相关资源
      最近更新 更多