subprocess.run,指令定义为字符串,只显示第一个空格前的命令的结果

问题遇到的现象和发生背景

subprocess.run插入命令的字符串,但是为什么,输出的结果不显示真实命令的结果,只显示“df”第一个空格前的结果

问题相关代码,请勿粘贴截图
storage_file = subprocess.run("df -mlT -x tmpfs -x devtmpfs -x iso9660 |grep -v '/boot' |grep -v '挂载点' |grep -v 'Mounted on' |grep -v 'overlay2' | sort -n -k 5 | tail -1 | awk '{print$NF}'",
                                  shell=True,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)

print("\n"+storage_file.stdout)
运行结果及报错内容

img

我的解答思路和尝试过的方法

已经加过了shell=True,理论上是可以加字符串的

我想要达到的结果

显示真实的,df -mlT -x tmpfs -x devtmpfs -x iso9660 |grep -v '/boot' |grep -v '挂载点' |grep -v 'Mounted on' |grep -v 'overlay2' | sort -n -k 5 | tail -1 | awk '{print$NF}'返回的结果。

换了一种写法,现在可以了,但是不知道什么原因。

class Text_formatting_toolbox:

    #Linux命令输出结果的格式化
    @staticmethod
    def scheduler_cmd(command):
        scheduler_order = command
        return_info = subprocess.Popen(scheduler_order, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        for next_line in return_info.stdout:
            return_line = next_line.decode("utf-8", "ignore").replace('\n', '')
            return return_line

# 安装路径选择
def Installation_path_selection():
    storage_file_name = Text_formatting_toolbox.scheduler_cmd(
        "df -mlT -x tmpfs -x devtmpfs -x iso9660 |grep -v '/boot' "
        "|grep -v '挂载点' |grep -v 'Mounted on' |grep -v 'overlay2' | "
        "sort -n -k 5 | tail -1 | awk '{print$NF}'")

    storage_file_space = Text_formatting_toolbox.scheduler_cmd(
        "df -mhl " + storage_file_name + " | awk 'NR==2{print $4}' | sed 's/G//g'")

    storage_file = [storage_file_name, int(storage_file_space)]

    return storage_file