首页 > 解决方案 > 如何在 Python 中使用 UNTAR 命令?

问题描述

我想用python中的命令替换os.system命令subprocess.call

D = "Some string value received at run time"
P = "Some string value received at run time"

Cmd = D + P + "| sudo /bin/tar -xvpPf - 1>> " + LoggerFile
untarCmd = os.WEXITSTATUS(os.system(Cmd))

现在我想os.systemsubprocess.call命令替换上面的内容。

pCmd = subprocess.Popen(shlex.split(D + P),shell=False,stdout=subprocess.PIPE)
untarCmd = subprocess.call(shlex.split("untarCmd"),shell=False,stdin=pCmd.stdout)

但接收错误

OSError: [Errno 2] No such file or directory
error writing output file

标签: pythonpython-2.7shellscripting

解决方案


推荐阅读