From 22ca3d32d3b5aba6823c5647209d534384e1f1c9 Mon Sep 17 00:00:00 2001 From: zart Date: Fri, 28 Jun 2024 11:35:14 +0800 Subject: [PATCH] msg MQTT message --- smp_coder/mqtt_smp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/smp_coder/mqtt_smp.py b/smp_coder/mqtt_smp.py index c9b92a7..072c5da 100644 --- a/smp_coder/mqtt_smp.py +++ b/smp_coder/mqtt_smp.py @@ -1,4 +1,5 @@ import os +import subprocess import paho.mqtt.client as mqtt import time @@ -54,7 +55,10 @@ client.publish("response/topic", "Set user.txt success!", qos=2) -os.system("sudo myenv/bin/python3 smp_coder/extur_smp.py > logex.txt 2>&1 &") +command = ["sudo", "myenv/bin/python3", "smp_coder/extur_smp.py"] +with open("logex.txt", "w") as log_file: + process = subprocess.Popen(command, stdout=log_file, stderr=log_file, bufsize=1, universal_newlines=True) + print("启动树莓派拍照客户端成功。") client.publish("response/topic", "启动树莓派拍照客户端成功", qos=2)