我有一個java應用程序,我只是在讀取文件並將數據插入到elasticsearch索引中。Elasticsearch REST api通過curl不能從java.runtime.exec工作
這是我正在使用的代碼。
in = new BufferedReader(new FileReader("file.txt"));
line = in.readLine();
while ((line = in.readLine()) != null) {
System.out.println("Command: curl -XPOST 'http://localhost:9200/esensor/data' -d '{ \"temp\": \""+line+"\" }'");
p = Runtime.getRuntime().exec("curl -XPOST 'http://localhost:9200/esensor/data' -d '{ \"temp\": \""+line+"\" }'");
p.waitFor();
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = err.readLine()) != null) {
System.out.println(line);
}
break;
}
in.close();
但這不起作用。捲毛是給這個錯誤。
curl: (1) Protocol 'http not supported or disabled in libcurl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: "temp"
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: "17.35757"
curl: (3) [globbing] unmatched close brace/bracket in column 1
但看到我打印了正在執行的命令。如果我手動複製在控制檯粘貼,然後一切工作正常。爲什麼會發生?我做錯了什麼?
爲什麼不使用elasticsearch的客戶端? [ElasticSearch客戶端](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html) – chengpohi
相關:http://stackoverflow.com/questions/16486649/shell- bash-brace-expansion-with-javas-runtime-exec –
@RC它與我的問題有何關係? –