Ubuntu / Python :无法从 SubProccess.Popen 启动 Chromium

Ubuntu / Python : Can't launch Chromium from SubProccess.Popen

基本上,我插入了一个 Arduino 来与我的计算机通信,目标是在我单击按钮时打开 Chromium。单击时,arduino 将在 serial communication 上发送一个字符串,计算机将通过 Python 脚本获取该字符串。

此脚本随后将使用 Popen(['chromium-brower'])

启动 Chromium

除了无法启动的 Chromium 之外,我已经能够毫无问题地完成所有这些操作。 syntaxe 是正确的,但终端 return 是一个我不明白的奇怪错误。

sudo python serialtest.py start [0825/084720:ERROR:nss_util.cc(96)] Failed to create /home/dlslabo/.pki/nssdb directory. [0825/084721:FATAL:chrome_main_delegate.cc(386)] Check failed: process_type.empty(). Unable to get the user data directory for process type: zygote #0 0x7f1a233095fe base::debug::StackTrace::StackTrace() #1 0x7f1a23325f8e logging::LogMessage::~LogMessage() #2 0x7f1a2f3a11f5 #3 0x7f1a2aa8f224 #4 0x7f1a2aa8d80d content::ContentMain() #5 0x7f1a2f3a065a #6 0x7f1a17a25a40 __libc_start_main #7 0x7f1a2f3a0519

这是我的 python 程序:

#!/usr/bin/env python

import serial
from subprocess import Popen

ser = serial.Serial('/dev/ttyACM0', 9600)

while 1 :
   line = ser.readline().strip()
   print line
   if line == "start":
      p = Popen(["chromium-browser"])

我尝试将其他应用程序作为 Popen(["gedit"])Popen(["firefox"]) 使用,效果很好。 从我在互联网上读到的内容来看,这可能是因为我正在以超级用户身份执行脚本。但我不知道为什么这会导致问题。

运行 作为 root 用户的浏览器(或任何其他不用于系统管理的程序)对于安全来说是个坏主意。

您似乎正在使用 root,因为您需要访问特定的设备节点。在这种情况下,您可以让非根用户成为设备的所有者。最简单的方法是通过 udev 规则。使用以下内容创建名为 /etc/udev/rules.d/99-tty-acm.rules 的文件:

KERNEL=="ttyACM0", OWNER="mynonrootuser", MODE=0660

如果更多用户可能需要访问权限,请为他们创建一个组,比如 ttyacm,然后设置 GROUP="ttyacm"MODE=0660More about writing udev rules here.