通过 udev 规则触发的 shell 脚本打开 lxterminal 窗口 [英] Open an lxterminal window via shell script triggered by udev rule

查看:99
本文介绍了通过 udev 规则触发的 shell 脚本打开 lxterminal 窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to start a python script that waits for user input via a shell script triggered by a UDEV rule. After the input arrives the python script needs to make some database calls. I'm running into a couple different issues.

这是udev规则:

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

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

Issue #1 - I can't seem to get it to actually open the window. Here is what I have in script.sh:

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

这是我从 udev 得到的错误:

Here is the error I'm getting from udev:

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

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

Here is another version of the shell script which actually ran, but wasn't visible, and crashed when checking for input. Guessing because I'll need to re-route stdin if I ever get the terminal to open? Script:

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

错误:

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

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

If I get rid of the input, I get this error:

[4859] exit with return code 0

这个答案听起来好像不可能,但这是编程任何事情都应该是可能的!https://unix.stackexchange.com/questions/119078/cannot-run-脚本使用 udev 规则

This answer makes it sound like this isn't possible, but this is programming anything is supposed to be possible! https://unix.stackexchange.com/questions/119078/cannot-run-script-using-udev-rules

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

The end of this forum sounds like it's possible, but I'll need to use Zenity? https://ubuntuforums.org/showthread.php?t=759389

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

Any info from someone that's more familiar with udev would be great!

推荐答案

For Issue #1;

For Issue #1;

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

这篇关于通过 udev 规则触发的 shell 脚本打开 lxterminal 窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆