PDA

View Full Version : Aiutino sintassi python "subprocess.Popen"


massimilianonball
31-01-2021, 16:34
Ciao a tutti, scrivo xké nell'ambito di un progetto amatoriale scritto al 99% in bash sono costretto ad usare anche qualche script in python, uno di questi è incollato sotto. In pratica monitora 2 variabili e se cambiano in modo significativo lancia uno script bash usandone i relativi valori come argomento:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#
import os
import subprocess
import time
#
pid = (os.getpid())
#
with open('/home/pi/logJARVIS/SERVICE/pythonPID.pid', 'w') as f:
f.write('%d' % pid)
#
from dronekit import connect
#
# Connect to the Vehicle (in this case a UDP endpoint)
vehicle = connect('127.0.0.1:14550', wait_ready=True)
#
aOLD = (vehicle.channels['7'])
bOLD = (vehicle.channels['8'])
#
count = 0
while count < 500000000000000000000000000000000000000000000000000000000000000000000000:
a = (vehicle.channels['7'])
b = (vehicle.channels['8'])
ris1 = a-aOLD
ris2 = b-bOLD
#
if (abs(ris1)) > 35 or (abs(ris2)) > 30:
print("<PYTHON> Ch1: %s" % a)
print("<PYTHON> Ch2: %s" % b)
subprocess.Popen(['/home/pi/logJARVIS/SERVICE/twinLT.sh', str(a), str(b)])
#
aOLD = a
bOLD = b
count += 1 # This is the same as count = count + 1
#
time.sleep(0.1)

Ultimamente ho aggiornato la pi e adesso lo script mi restituisce questo errore:

Traceback (most recent call last):
File "camera03mavp.py", line 46, in <module>
subprocess.Popen('/home/pi/logJARVIS/SERVICE/twinLT.sh', str(a))
File "/usr/lib/python2.7/subprocess.py", line 343, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

Qualcuno può aiutarmi con il comando "subprocess.Popen", leggendo in rete dovrebbero essere cambiate le sintassi ma non riesco a venire a capo del problema..

Kaya
01-02-2021, 13:42
Sicuro di aver postato il codice giusto?
Perchè dice
File "camera03mavp.py", line 46, in <module>
Ma il file in tutto ha 38 righe...