简体   繁体   English

插入USB时自动运行python文件

[英]Auto run python file when usb inserted

I have a Raspberry Pi running Linux.我有一个运行 Linux 的 Raspberry Pi。 My plan is that I can plug in a USB in the robot and have and it will run the python files.我的计划是我可以在机器人中插入 USB 并运行 python 文件。 the reason I chose this method is that it allows for easy editing and debugging of the scripts.我选择这种方法的原因是它允许轻松编辑和调试脚本。

Is there a way to execute my files when the USB is inserted?有没有办法在插入 USB 时执行我的文件?

尝试使用 os.path.exists 来检测 pendrive 是否在无限循环中,当检测到时,使用 os.system 在 pendrive 上执行代码并跳出循环。

Check this link out: https://ubuntuforums.org/showthread.php?t=1648939查看此链接: https : //ubuntuforums.org/showthread.php?t=1648939

Looks like you should consider writing a script that navigates to the directory of the file and runs "python yourscript.py".看起来您应该考虑编写一个导航到文件目录并运行“python yourscript.py”的脚本。 The details on getting the script to autorun are there.那里有关于让脚本自动运行的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM