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)