diff --git a/MQTT.py b/MQTT.py index d7c532e..2c4ed34 100644 --- a/MQTT.py +++ b/MQTT.py @@ -23,7 +23,7 @@ class MQTT: client.publish('success', payload='close_stream success', qos=0) elif data == "exec": # 执行命令 - exec_sh(msg) + exec_sh(msg, client) client.publish('success', payload='exec_sh success', qos=0) elif data == "update": # git更新项目和配置文件 diff --git a/tool.py b/tool.py index d653ce4..ebf2029 100644 --- a/tool.py +++ b/tool.py @@ -15,14 +15,14 @@ def close_stream(): subprocess.Popen(['/bin/bash stop_push.sh'], shell=True) -def exec_sh(msg): +def exec_sh(msg, client): cmd = json.loads(msg.payload.decode('utf-8'))["data"] if cmd == "supervisorctl stop __mqtt__": return p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() output = out.decode('utf-8') - print(output) + client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0) def update():