簡體   English   中英

使用Python子流程調用SOLR發布工具命令

[英]Invoke SOLR post tool command using Python subprocess

我想通過Python子進程調用此SOLR post命令:

/u01/tony/solr-7.5.0/bin/post -c techproducts /u01/tony/data/bbc/politics/*.txt -params "literal.keywords=politics"

我嘗試使用python子流程模塊觸發此操作,如下所示:

subprocess.run(["/u01/tony/solr-7.5.0/bin/post -c techproducts /u01/tony/data/bbc/politics/*.txt -params", "literal.keywords=politics"], stdout=PIPE, stderr=PIPE)

但這會引發以下錯誤:

FileNotFoundError: [Errno 2] No such file or directory: '/u01/tony/solr-7.5.0/bin/post -c techproducts /u01/tony/data/bbc/politics/*.txt -params': '/u01/tony/solr-7.5.0/bin/post -c techproducts /u01/tony/data/bbc/politics/*.txt -params'

您需要拆分所有參數-第一個參數是要運行的命令。

["/u01/tony/solr-7.5.0/bin/post", "-c", "techproducts", "/u01/tony/data/bbc/politics/*.txt", "-params", "literal.keywords=politics"

另外,請注意, *.txt擴展是由您的Shell完成的,因此,如果未在Shell上下文中調用命令(..不在此處),則不會對其進行擴展。 但是,由於bin/post工具接受目錄作為直接參數,並且具有-filetypes參數,因此可以使用

"-filetypes txt", "/u01/tony/data/bbc/politics/"

..代替。

bin/post工具也是一個shell腳本,因此,如果它不允許直接調用(我不確定如何解決),則可能必須在調用數組前添加

"/usr/bin/env", "bash"

也一樣

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM