我使用Python下载了bz2文件。然后我想用来解包:在Python中解压缩出错
def unpack_file(dir, file):
cwd = os.getcwd()
os.chdir(dir)
print "Unpacking file %s" % file
cmd = "tar -jxf %s" % file
print cmd
os.system(cmd)
os.chdir(cwd)
不幸的是这与错误结束:
bzip2: Compressed file ends unexpectedly;
perhaps it is corrupted? *Possible* reason follows.
bzip2: Inappropriate ioctl for device
Input file = (stdin), output file = (stdout)
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.
tar: Nieoczekiwany EOF w archiwum
tar: Nieoczekiwany EOF w archiwum
tar: Error is not recoverable: exiting now
但是我可以从解包壳归档,没有任何问题。
你有什么想法我做错了吗?
你能告诉我们你在shell中运行的确切命令,确切的命令(包括文件名),你传递给'OS 。系统()'? – NPE 2012-01-17 10:57:53
请使用['subprocess.Popen'](http://docs.python.org/library/subprocess.html#replacing-os-system)而不是'os.system'。 – jcollado 2012-01-17 11:14:54
你是如何下载文件的?如果你在解压缩之前先进入睡眠(15),那么是否仍然有相同的错误? – Foon 2012-01-17 20:29:21