[英]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.