Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • Subprocess Fails to Run

$
0
0
Goal:
To use a barcode scanner to execute a specific script.



Process:

1. Operator scans part number barcode on build sheet. (Example: 12345).

2. "barcodeTest1.py" takes that input and defines the program number (prog_number) as the input() + ".py"

3. "barcodeTest1.py" runs prog_number.py



Problem:

For the example below, the part number and program number will be 12345. "barcodeTest1.py" does not seem to execute the subprocess "12345.py". The LED does not blink. If I run 12345.py separately, it works as expected. Why does the LED not start blinking when 12345.py is run as a subprocess inside of barcodeTest1.py?







barcodeTest1.py:

Code:

import subprocess print("Scan barcode")prog_number = input() + ".py"print(prog_number) subprocess.run(['python3', prog_number], shell = True)


12345.py:

Code:

import timeimport RPi.GPIO as GPIO GreenLED = 12RedLED = 16  GPIO.setwarnings(False)GPIO.setmode(GPIO.BCM)GPIO.setup(GreenLED, GPIO.OUT)GPIO.setup(RedLED, GPIO.OUT)while True:                GPIO.output(GreenLED, GPIO.HIGH)                GPIO.output(RedLED, GPIO.LOW)                else:                                print('failure')

Statistics: Posted by Short to GND — Fri Nov 15, 2024 5:10 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles