我从 github gtfs_SQL_importer 复制了以下代码:
cat gtfs_tables.sql \
<(python import_gtfs_to_sql.py path/to/gtfs/data/directory) \
gtfs_tables_makeindexes.sql \
vacuumer.sql \
| psql mydbname
我尝试在 Windows 上运行它,并用 Windows 等效 type
替换了对 UNIX 命令 cat
的调用,这应该与 is-there-replacement-for-cat-on-windows 类似.
然而,当我执行该代码时,出现了一些错误:
The syntax for the filename, directory or filesystem is wrong.
所以我试图限制管道文件的数量,只结合对 python 的调用和对 psql
的调用:
type <(C:/python27/python path/to/py-script.py path/to/file-argument) | psql -U myUser -d myDatabase
这会导致相同的错误。
然而,当我单独执行 python 脚本时,它会按预期工作:
C:/python27/python path/to/py-script.py path/to/file-argument
所以我假设错误是由于使用 type
将脚本的结果直接通过管道传递给 psql
造成的。
有人知道正确的语法吗?
编辑:为了确保问题与未找到的文件无关,我对命令中的所有参数使用了绝对路径,type
和 psql
命令除外(它们都通过 %PATH%
变量处理)。
最佳答案
安装 cygwin并在 Windows 上使用 unix cat。
关于python - 如何通过管道传输多个 sql 和 py 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44230747/