繁体   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