浏览代码

Update shell_execute.py

qiaofeng1227 2 年之前
父节点
当前提交
17ae6182ef
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      appmanage/api/utils/shell_execute.py

+ 2 - 2
appmanage/api/utils/shell_execute.py

@@ -14,7 +14,7 @@ def execute_command_output_all(cmd_str, max_time = 3):
     myLogger.info_logger("Start to execute cmd: " + cmd_str)
     execute_time = 0
     while execute_time < max_time:
-        process = subprocess.run(f'nsenter -m -u -i -n -p -t 1 sh -c "{cmd_str}"', capture_output=True, check=True, text=True, shell=True)
+        process = subprocess.run(convert_command(cmd_str), capture_output=True, check=True, text=True, shell=True)
         if process.returncode == 0:
             return {"code": "0", "result": process.stdout,}
         else:
@@ -28,6 +28,6 @@ def convert_command(cmd_str):
     if cmd_str == "":
        convert_cmd=cmd_str
     else:
-       convert_cmd="f nsenter -m -u -i -n -p -t 1 sh -c " +cmd_str
+       convert_cmd="nsenter -m -u -i -n -p -t 1 sh -c " + "'"+cmd_str+"'"
 
     return convert_cmd