【问题标题】:Python subprocess.call tar command to use the uncompressed files laterPython subprocess.call tar 命令稍后使用未压缩的文件
【发布时间】:2018-02-07 23:04:50
【问题描述】:

我正在尝试解压缩扩展名为 .gz 的 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的正确方法吗?

【问题讨论】:

    标签: python python-2.7 postgresql subprocess


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 2019-06-14
      • 2017-10-27
      • 2015-09-22
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      相关资源
      最近更新 更多