【发布时间】:2014-02-28 09:07:05
【问题描述】:
我正在尝试使用 Popen 执行命令。
该命令使用一些 PostGIS/Postgresql 实用程序将光栅文件上传到数据库,并在从命令行执行时工作。它使用 unix 风格的管道来链接 2 个命令,如下所示:
"C:\\Program Files\\PostgreSQL\\9.2\\bin\\raster2pgsql.exe" -d -I -C -e -Y -F -t 128x128 "C:\\temp\\SampleDTM\\SampleDTM.tif" test | "C:\\Program Files\\PostgreSQL\\9.2\\bin\\psql.exe" -h localhost -p 5432 -d adr_hazard -U postgres
在 Python 中使用时,我将其设为带有 ' 代码的字符串:
command = '"C:\\Program Files\\PostgreSQL\\9.2\\bin\\raster2pgsql.exe" -d -I -C -e -Y -F -t 128x128 "C:\\temp\\SampleDTM\\SampleDTM.tif" test | "C:\\Program Files\\PostgreSQL\\9.2\\bin\\psql.exe" -h localhost -p 5432 -d adr_hazard -U postgres'
尝试执行它会导致错误:
p = subprocess.Popen(command)
ERROR: Unable to read raster file: test
错误似乎是命令未正确解析(它将错误的参数解释为光栅文件)
我用Popen 错了吗?
【问题讨论】:
-
尝试
subprocess.Popen(["C:\\Program Files\\PostgreSQL\\9.2\\bin\\raster2pgsql.exe", '-d', '-I', '-C', '-e', '-Y', '-F', '-t', '128x128', "C:\\temp\\SampleDTM\\SampleDTM.tif", 'test'']),如果它工作,然后在PIPE中输出。
标签: python postgresql subprocess popen raster