[英]Invoke SOLR post tool command using Python subprocess
I want to invoke this SOLR post command through 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"
I tried firing this using python subprocess module as follows: 我尝试使用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)
But this throws the following error: 但这会引发以下错误:
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'
You need to split all your arguments - the first argument is the command to run. 您需要拆分所有参数-第一个参数是要运行的命令。
["/u01/tony/solr-7.5.0/bin/post", "-c", "techproducts", "/u01/tony/data/bbc/politics/*.txt", "-params", "literal.keywords=politics"
Also, be aware that the *.txt
expansion is done by your shell, so if the command is not invoked in a shell context (.. which it isn't here), it won't be expanded. 另外,请注意,
*.txt
扩展是由您的Shell完成的,因此,如果未在Shell上下文中调用命令(..不在此处),则不会对其进行扩展。 However, since the bin/post
tool accepts a directory as a direct parameter and has a -filetypes
parameter, you can use 但是,由于
bin/post
工具接受目录作为直接参数,并且具有-filetypes
参数,因此可以使用
"-filetypes txt", "/u01/tony/data/bbc/politics/"
.. instead. ..代替。
The bin/post
tool is also a shell script, so if it doesn't allow direct invocation (I'm not sure how this is resolved), you might have to prepend the invocation array with bin/post
工具也是一个shell脚本,因此,如果它不允许直接调用(我不确定如何解决),则可能必须在调用数组前添加
"/usr/bin/env", "bash"
as well. 也一样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.