简体   繁体   English

ShellScript文件未执行以删除Elasticsearch索引

[英]ShellScript File not executing for delete elasticsearch index

Hi I have an elasticsearch index which needs to deleted when a new entry of that type has inserted. 嗨,我有一个Elasticsearch索引,当插入了该类型的新条目时,需要删除该索引。 I was able create a shellscript file and insert data into elasticsearch with a java appliaction as below, 我能够创建一个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 Test.sh

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

With my java program it was possible to insert data but I can't delete, I tried to run the above command in command-line and it worked fine. 使用我的Java程序,可以插入数据,但无法删除,我尝试在命令行中运行以上命令,但效果很好。 What is happening here? 这是怎么回事 Why is it executing in command-line and not in my program? 为什么它在命令行而不是在我的程序中执行?

Does your Java program know what "sh" is? 您的Java程序是否知道“ sh”是什么? Have you tried fully qualifying the command: 您是否尝试过完全限定命令:

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

What is the error when it doesn't run? 不运行时有什么错误? Is it best practice to run a shell script in a Java program? 在Java程序中运行Shell脚本是最佳实践吗? Are there other ways of running commands in Java programs? 在Java程序中还有其他运行命令的方式吗?

java Runtime.exec to run shell script java Runtime.exec以运行Shell脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM