Permissions 如何以root身份从节点red执行python脚本

Permissions 如何以root身份从节点red执行python脚本,permissions,raspberry-pi,exec,node-red,Permissions,Raspberry Pi,Exec,Node Red,如何使用root权限运行节点red exec块 我有两个python脚本,camera.py和relay.py。我能够执行camera.py,但无法从节点red执行relay.py 我能够通过命令行无误地运行以下命令:“./camera.py”、“sudo./camera.py”、“sudo./relay.py 200”。 我无法运行“/relay.py 200”,因为它给我一个执行错误。我认为这是因为它使用SpiDev,它通常需要root权限 从节点red exec块,我可以无错误地执行以下操

如何使用root权限运行节点red exec块

我有两个python脚本,camera.py和relay.py。我能够执行camera.py,但无法从节点red执行relay.py

我能够通过命令行无误地运行以下命令:“./camera.py”、“sudo./camera.py”、“sudo./relay.py 200”。 我无法运行“/relay.py 200”,因为它给我一个执行错误。我认为这是因为它使用SpiDev,它通常需要root权限

从节点red exec块,我可以无错误地执行以下操作: “camera.py”和“sudo camera.py”。 但是,我不知道如何执行“relay.py 200”

以下是relay.py代码:

#!/usr/bin/python
import sys
import spidev
hexForm = format(int(sys.argv[1]),'#04x')
spiBus = 0
spiChannel = 0 #SPI Channel (CE0) 
spi = spidev.SpiDev()
spi.open(spiBus,spiChannel)
to_send = hexForm
spi.xfer(to_send)
以下是节点红色流:

[{"id":"b77b1a31.7df568","type":"http in","z":"56302dc4.e31264","name":"RelayRequest","url":"/RelayRequest","method":"post","swaggerDoc":"","x":95,"y":197,"wires":[["78e73048.889a7","702908ee.357d18"]]},{"id":"ef17aada.044c18","type":"http response","z":"56302dc4.e31264","name":"Return","x":797,"y":207,"wires":[]},{"id":"37db2a8.1eeafd6","type":"exec","z":"56302dc4.e31264","command":"sudo python-scripts/relay.py","addpay":true,"append":"","useSpawn":"","timer":"","name":"ExecRelayScript","x":455,"y":250,"wires":[["cf28fa90.0d7c08","ef17aada.044c18"],["9b8b4782.ebc578"],["48066a13.83d884"]]},{"id":"9b8b4782.ebc578","type":"debug","z":"56302dc4.e31264","name":"stderror2","active":true,"console":"false","complete":"payload","x":648,"y":311,"wires":[]},{"id":"cf28fa90.0d7c08","type":"debug","z":"56302dc4.e31264","name":"stdout2","active":true,"console":"false","complete":"payload","x":812,"y":273,"wires":[]},{"id":"48066a13.83d884","type":"debug","z":"56302dc4.e31264","name":"return code2","active":true,"console":"false","complete":"payload","x":684,"y":361,"wires":[]},{"id":"78e73048.889a7","type":"function","z":"56302dc4.e31264","name":"function","func":"if(msg.req.body)\n{\n    msg.payload = msg.req.body\n    return msg;\n}\n","outputs":1,"noerr":0,"x":263,"y":251,"wires":[["37db2a8.1eeafd6","5f0cf4ac.3cb30c"]]},{"id":"5f0cf4ac.3cb30c","type":"debug","z":"56302dc4.e31264","name":"function out","active":true,"console":"false","complete":"payload","x":470,"y":164,"wires":[]},{"id":"702908ee.357d18","type":"debug","z":"56302dc4.e31264","name":"stdout2","active":true,"console":"false","complete":"req.body","x":301,"y":108,"wires":[]}]
我删除了将其转换为字符串的format()部分。它现在似乎正在工作