【发布时间】:2020-01-22 14:44:16
【问题描述】:
这个命令运行:
process_1 = subprocess.Popen("gzip -dc " + infile + " > " + inter_file,
cwd = base_dir,
stdout = subprocess.PIPE,
shell = True,
universal_newlines = True)
output, error = process_1.communicate()
现在,我想删除shell=True(我有很多类似上面的行和
我怀疑Shell = True 会导致内存泄漏):
process_1 = subprocess.Popen(["gzip", "-dc", infile, ">", inter_file],
cwd = base_dir,
stdout = subprocess.PIPE,
shell = False,
universal_newlines = True)
output, error = process_1.communicate()
产量:
gzip: > .gz: No such file or directory
gzip: blabla.txt: not in gzip format
但blabla.txt 是inter_file:似乎设置Shell = False 混淆了infile 和inter_file。如何解决?
附:欢迎提供一般性答案。我有 50 个类似上述的系统调用,需要重新格式化才能在 Shell = False 模式下运行。
【问题讨论】:
标签: python unix subprocess