Any way to execute a piped command in Python using subprocess module, without using shell=True?

后端 未结 4 1392
别跟我提以往
别跟我提以往 2020-12-28 09:27

I want to run a piped command line linux/bash command from Python, which first tars files, and then splits the tar file. The command would look like something this in bash:<

4条回答
  •  被撕碎了的回忆
    2020-12-28 10:00

    tar can split itself:

    tar -L 1000000 -F name-script.sh cf split.tar largefile1 largefile2 ...
    

    name-script.sh

    #!/bin/bash
    echo "${TAR_ARCHIVE/_part*.tar/}"_part"${TAR_VOLUME}".tar >&"${TAR_FD}"
    

    To re-assemble

    tar -M -F name-script.sh cf split.tar
    

    Add this to your python program.

提交回复
热议问题