子进程不写入输出文件

subprocess doesn't write the output file

我在 jupyter notebook 中使用 python。

我要执行以下命令:

$ gdalbuildvrt tmp_merge files

其中 tmp_merge 是函数的输出文件并设置为:/home/prambaud/gfc_results/test/tmp_tile.vrt
filesvrt 文件中要合并的所有图块设置为:/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 notebook 的命令 ! 和相同的参数,当然蜜蜂创建了 tmp 文件...

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

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