2017-05-28 44 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

相關問題