嗨,我有一个elasticsearch索引,当插入该类型的新条目时,该索引需要删除。我创建了一个below脚本文件并使用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程序可以插入数据,但我不能删除,我尝试在命令行中运行上面的命令,它运行得很好。这里发生了什么事?为什么它在命令行而不是在我的程序中执行?
发布于 2017-09-21 21:08:53
你的Java程序知道什么是"sh“吗?您是否尝试过对命令进行完全限定:
Process p = Runtime.getRuntime().exec("/bin/sh src/resources/test.sh");
当它不运行时,错误是什么?在Java程序中运行shell脚本是最佳实践吗?在Java程序中还有其他运行命令的方法吗?
https://stackoverflow.com/questions/46357128
复制相似问题