Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

python - 如何在Python中使用UNTAR命令?(How to use UNTAR command in Python?)

I want to replace os.system command with subprocess.call command in python.

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

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

(D =“在运行时收到一些字符串值” P =“在运行时收到一些字符串值”)

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

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

Now I want to replace above os.system with subprocess.call command.

(现在我想用subprocess.call命令替换上面的os.system。)

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

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

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

(但是收到错误OSError:[Errno 2]写入输出文件时没有此类文件或目录错误)

  ask by james translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...