我使用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