2017-08-30 73 views
0

我想解压缩tar文件以.gz扩展这一说法后的Python subprocess.call tar命令后使用未压缩的文件

status = subprocess.call('tar -zvxf %s -C %s 2> /dev/null' % (zipped_tar_file,data_path), shell=True) 

不久,我还有一个呼叫 -

status = subprocess.call('psql -q -v PATH=%s -f %s -h %s -p %d %s' %(some params) 

第二条语句告诉postgres使用第一条命令提取的一些文件。我在postgres中得到一个文件不存在的错误。

它看起来像tar命令仍在运行,而第二条语句已经启动,postgres找不到所需的文件还没有被提取。

ERROR: could not open file "path/filename.csv" for reading: No such file or directory 

filename.csv是从tarball中提取的文件之一。

的文件是有点重

这是使用subprocess.call正确的方式(几兆字节的hundered)?

回答

0

由于subprocess.call()需要时间执行,所以可以在执行两个命令之间添加时间延迟。

您可以检查:Python subprocess timeout?以获得更详细的答案。