2017-05-28 46 views
9

我从github gtfs_SQL_importer复制下面的代码:如何管多个SQL-和PY-脚本

cat gtfs_tables.sql \ 
    <(python import_gtfs_to_sql.py path/to/gtfs/data/directory) \ 
    gtfs_tables_makeindexes.sql \ 
    vacuumer.sql \ 
    | psql mydbname 

我试图在Windows上运行这一点,并通过窗口相当于取代了调用UNIX命令cattype这应该与is-there-replacement-for-cat-on-windows的工作类似。

然而,当我执行的代码,我得到了一些错误:

the syntax for the filename, directory or filesystem is whrong.

于是,我就的管道文件的数量限制为仅结合调用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错误的结果。

有谁知道正确的语法?

编辑:为确保问题不相关的文件不被发现,我用我的命令之内的所有参数的绝对路径,除了typepsql -command(这是通过%PATH% -variable都处理)。

+1

你确定你的语法正确吗?你在'type'后面有一个重定向操作符。你可以试着做:'输入gtfs_tables.sql <(C:/ python27/python path/tp/py-script.py path/to/file-argument)| psql -U myUser -d myDataBase'? – puelo

+0

截至http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true'<'-command应该从我的python脚本读取数据并发送到管道(在我的情况下''psql')。不过,我还在'<'之前添加了第一个sql文件,这会产生相同的消息。 – HimBromBeere

+0

这个部分的输出是什么'type <(C:/ python27/python path/to/py-script.py path/to/file-argument)'? – zenlc2000

回答

2

Comment: So I can´t combine the sql-files and the output from my pythonscript together and pipe them to psql?

另一种方法,创建自己的cat与Python, 涨幅前三行的代码添加到import_gtfs_to_sql.py, 例如:

# Usage 
python import_gtfs_to_sql.py... | python myCat.py gtfs_tables.sql | psql mydbname 

#myCat.py 
import sys 
with open(sys.argv[1]) as fh: 
    sys.stdout.write(fh.read()) 

sys.stdout.write(sys.stdin.read()) 

Comment: I allready know the error comes from type<(python...)

TYPE命令不接受stdin
因此,您唯一的解决方案是选项2.

另一种方法是使用您的Python脚本来做print gtfs_tables.sql


Question: the syntax for the filename, directory or filesystem is whrong.

  1. 找出从部分上述错误的来源。

    a) type gtfs_tables.sql 
    b) type <(python ... 
    c) type gtfs_tables.sql <(python ... 
    d) type gtfs_tables.sql | psql mydbname 
    e) type <(python ... | psql mydbname 
    
  2. <(python ...输出保存到一个文件,并尝试

    python ... > tmp_python_output 
    type gtfs_tables.sql tmp_python_output | psql mydbname 
    
+0

我已经知道错误来自'type <(python ...)'。因此,你的答案根本不能解决问题。 “ – HimBromBeere

+0

”TYPE命令不接受标准输入。“所以我不能将sql-files和我的pythonscript的输出结合在一起,并将它们传递给psql?悲伤,但谢谢你的提示。 – HimBromBeere

+0

似乎工作。谢谢。 – HimBromBeere