我想通过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"
同样。