我正在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文件……
答案 0 :(得分:0)
我的命令只能从shell执行,因此在使用子进程时,我需要将shell
关键字添加为:
process = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
shell=True
)