子进程不写入输出文件



我正在jupyter笔记本中使用python。

我想执行以下命令:

$ gdalbuildvrt tmp_merge files

其中tmp_merge是函数的输出文件并设置为:/home/prambaud/gfc_results/test/tmp_tile.vrt
files是要在vrt文件中合并的所有瓦片并设置为/home/prambaud/gfc_results/test/tile_*.tif

此函数授权使用通配符。

为了在我的Jupyter笔记本上运行它,我使用subprocess模块:

command = [
'gdalbuildvrt',
'/home/prambaud/gfc_results/test/tmp_tile.vrt',
'/home/prambaud/gfc_results/test/tile_*.tif'
]
process = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
#cwd=os.path.expanduser('~')
)

print(process. stdout)

结果我得到了以下结果:

0...10...20...30...40...50...60...70...80...90...100 - done.

没有错误消息。但是没有创建输出文件。有人知道什么可以阻止subprocess.run函数在文件中创建和写入吗?

PS:
我也尝试过用!从jupyter笔记本上运行命令,当然创建了相同的参数和tmp文件。。。

我的命令只能从shell执行,因此使用子流程我需要添加shell关键字作为:

process = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
shell=True
)

最新更新