【问题标题】:How can i run and return the cassandra nodetool command and its output我如何运行并返回 cassandra nodetool 命令及其输出
【发布时间】:2018-01-31 18:30:47
【问题描述】:

如何使用 Java 运行和返回 cassandra nodetool 命令及其输出。我检查了this SO question,但不清楚具体如何操作。

【问题讨论】:

  • 你的用例是什么?也许您可以从 JMX 中获取这些信息或通过 JMX 运行一些命令。
  • 我想在 java 中运行任何 nodetool 命令并获取输出

标签: cassandra cql nodetool


【解决方案1】:
import java.io.InputStreamReader;

public class ShellTest {
     public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException {
            // Get runtime
            java.lang.Runtime rt = java.lang.Runtime.getRuntime();
            // Start a new process: UNIX command ls
            java.lang.Process p = rt.exec("ccm node1 nodetool status");
            // You can or maybe should wait for the process to complete
            p.waitFor();
            System.out.println("Process exited with code = " + p.exitValue());
            // Get process' output: its InputStream
            java.io.InputStream is = p.getInputStream();
            java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is));
            // And print each line
            String s = null;
            while ((s = reader.readLine()) != null) {
                System.out.println(s);
            }
            is.close();
        }
}

【讨论】:

    猜你喜欢
    • 2019-03-17
    • 2011-12-11
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多