Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elasticsearch REST api通过curl从java.runtime.exec不工作_Java_Curl_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Libcurl - Fatal编程技术网 elasticsearch,libcurl,Java,Curl,elasticsearch,Libcurl" /> elasticsearch,libcurl,Java,Curl,elasticsearch,Libcurl" />

Elasticsearch REST api通过curl从java.runtime.exec不工作

Elasticsearch REST api通过curl从java.runtime.exec不工作,java,curl,elasticsearch,libcurl,Java,Curl,elasticsearch,Libcurl,我有一个java应用程序,在其中我只是读取一个文件并将数据插入elasticsearch索引 这是我正在使用的代码 in = new BufferedReader(new FileReader("file.txt")); line = in.readLine(); while ((line = in.readLine()) != null) { System.out.println("Command: curl -XPOST

我有一个java应用程序,在其中我只是读取一个文件并将数据插入elasticsearch索引

这是我正在使用的代码

        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给出了这个错误

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

但是我已经打印了我正在执行的命令。如果我在控制台中手动复制粘贴,那么一切正常。为什么会这样?我做错了什么

curl的错误消息中有一个键:

curl: (1) Protocol 'http not supported or disabled in libcurl

协议名称前的单引号表示curl作为参数的一部分被传递,因此它不能按您希望的方式工作,而是给curl一个格式错误的URL。

curl的错误消息中有一个键:

curl: (1) Protocol 'http not supported or disabled in libcurl

协议名称前的单引号显示curl作为参数的一部分被传递,因此它不能按您希望的方式工作,而是给curl一个格式错误的URL。

为什么不使用elasticsearch的客户端?相关:@RC它与我的问题有什么关系???@chengpohi我只是想用exec来做。原因使用客户端将导致更多内存消耗。在我的例子中,这段代码可能运行在1000-10000个线程或更多线程中。所以我想如果exec只会减少内存消耗。也许我错了。使用runtime.exec是不可能的吗?我想您应该发出的是大括号
{}
解释尝试转义它们为什么不使用elasticsearch的客户端?相关:@RC它与我的问题有什么关系???@chengpohi我只是想用exec来做。原因使用客户端将导致更多内存消耗。在我的例子中,这段代码可能运行在1000-10000个线程或更多线程中。所以我想如果exec只会减少内存消耗。也许我错了。使用runtime.exec是不可能的吗?我想您应该发出的是大括号
{}
解释尝试转义它们为什么不使用elasticsearch的客户端?相关:@RC它与我的问题有什么关系???@chengpohi我只是想用exec来做。原因使用客户端将导致更多内存消耗。在我的例子中,这段代码可能运行在1000-10000个线程或更多线程中。所以我想如果exec只会减少内存消耗。也许我错了。使用runtime.exec不可能吗?我想您可能会发出Is-brages
{}
解释,尝试转义它们。您能给我在runtime.exec中必须发送的正确命令吗??请告诉我,我找不到任何工作。Runtime.getRuntime().exec显然不支持常规的shell样式引用。你最好仔细看看细节。我不知道,我只是在解释curl说的话……你能给我一个正确的命令吗?我必须在运行时发送这个命令。exec??请告诉我,我找不到任何工作。Runtime.getRuntime().exec显然不支持常规的shell样式引用。你最好仔细看看细节。我不知道,我只是在解释curl说的话……你能给我一个正确的命令吗?我必须在运行时发送这个命令。exec??请告诉我,我找不到任何工作。Runtime.getRuntime().exec显然不支持常规的shell样式引用。你最好仔细看看细节。我不知道,我只是在解释curl说的话。。。