usb怎么驱动怎么编程python_如何在USB闪存驱动器插入上运行Python脚本

RUN{type}

Add a program to the list of programs to be executed after

processing all the rules for a specific event,depending on "type":

"program"

Execute an external program specified as the assigned value. If

no absolute path is given,the program is expected to live in

/lib/udev; otherwise,the absolute path must be specified.

This is the default if no type is specified.

"builtin"

As program,but use one of the built-in programs rather than an

external one.

The program name and following arguments are separated by spaces.

Single quotes can be used to specify arguments with spaces.

This can only be used for very short-running foreground tasks.

Running an event process for a long period of time may block all

further events for this or a dependent device.

Starting daemons or other long-running processes is not appropriate

for udev; the forked processes,detached or not,will be

unconditionally killed after the event handling has finished.

从udev手册页,请特别注意最后2段.

我的猜测是,你发现了无条件的杀戮部分

编辑1年后:

在有人投票之后我重新审视了这个问题,我已经解决了问题,即root(运行此流程的人)没有X终端条目,对于某些事情,例如notify-send或启动Gui程序,仍然存在如前所述,事件发生后仍然是杀戮过程.

当插入USB设备时,以下内容向终端发送通知并启动wxPython Gui程序.

剧本:

#!/bin/sh

DISPLAY=:0

export DISPLAY

/usr/bin/notify-send "Usb Device detected" "Starting Reminder program" | at now

/usr/bin/python3 /home/rolf/reminders/reminders2.1.0/reminder.py | at now

通过定义DISPLAY,我们可以解决root的无X条目输入问题

通过将我们希望运行的命令传递给at程序以及现在运行它的指令,我们避免了udev杀死进程.

/lib/udev/rules.d/10-usbinsert.rules文件:

KERNEL=="sd*[!0-9]|sr*",RUN+="/usr/bin/sudo -u rolf /home/rolf/script.sh &"

我希望这有助于或让你朝着正确的方向前进.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值