开发者

Untarring in python, interactive vs script call

I am trying to untar a tar file via popen (from platform import popen) and am running into problems. The command runs if I use the interactive script, but does not if I put it in a .py fi开发者_如何学JAVAle and run it.

Basically, I change to to that directory and run popen("tar xvf the_tar.tar")

Why would these be different? How come it does not run in the script? Identical code between the interactive session and the script!

Edit:

The exact script is as follows

import os, time
from platform import popen

os.chdir("C:/testing/")
popen("tar -xvf the_tar.tar")


You should use the tarfile library:

from tarfile import TarFile

tar = TarFile("the_tar.tar")
tar.extractall()


Given your info I can't see the problems you see. Probably a bit more of context. I.e. the exact script that does not work, please.

I built a sample tar archive with an empty text file in it. Then I typed a two line python script inside this folder:

from platform import popen
popen("tar xvf the_tar.tar")

As I ran it, it gave me:

x sample.txt

as expected. The error must happen inside your script. As with the now shown script in the question this also runs on my mac when I change the os.chdir() argument to a for me appropriate "./".

Could you test it modified to os.chdir("./") on your machine (windows I guess)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜