Python 3.x 使用Python子流程调用SOLR post工具命令
我想通过Python子流程调用此SOLR post命令:Python 3.x 使用Python子流程调用SOLR post工具命令,python-3.x,solr,subprocess,Python 3.x,Solr,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/dat
/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"
还有。您需要拆分所有参数-第一个参数是要运行的命令
["/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"
还有。错误说明了什么?错误说明了什么?