簡體   English   中英

ShellScript文件未執行以刪除Elasticsearch索引

[英]ShellScript File not executing for delete elasticsearch index

嗨,我有一個Elasticsearch索引,當插入了該類型的新條目時,需要刪除該索引。 我能夠創建一個shellscript文件,並使用以下Java應用程序將數據插入elasticsearch中,

public static void main(String[] args) {
    try {
        // Run the process
        /*Runtime.getRuntime().exec("cd src/resources");*/
        Process p = Runtime.getRuntime().exec("sh src/resources/test.sh");
        // Get the input stream
        InputStream is = p.getInputStream();

        // Read script execution results
        int i;
        StringBuffer sb = new StringBuffer();
        while ((i = is.read()) != -1)
            sb.append((char) i);

        System.out.println(sb.toString());

    } catch (IOException e) {
        e.printStackTrace();
    }
}

Test.sh

curl -XDELETE http://localhost:9200/pokedex

使用我的Java程序,可以插入數據,但無法刪除,我嘗試在命令行中運行以上命令,但效果很好。 這是怎么回事 為什么它在命令行而不是在我的程序中執行?

您的Java程序是否知道“ sh”是什么? 您是否嘗試過完全限定命令:

 Process p = Runtime.getRuntime().exec("/bin/sh src/resources/test.sh");

不運行時有什么錯誤? 在Java程序中運行Shell腳本是最佳實踐嗎? 在Java程序中還有其他運行命令的方式嗎?

java Runtime.exec以運行Shell腳本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM