如何运行此命令“check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%”来自 Java 代码?

发布于 2024-12-26 00:19:00 字数 364 浏览 2 评论 0原文

您好,我正在使用 linux,并尝试在 java 中执行此命令,并愿意在字符串变量中获取其结果,我已使用 inetaddress 来 ping 主机,但我需要运行此命令。它在“nagios”中使用,也许它会使用它自己的命令我想在这个模式中执行这个命令?

http://nagios.sourceforge.net/docs/3_0/macros.html 上面的链接是为了帮助

How it would be possible 

希望您的建议

提前致谢

hi i am using linux and trying to execute this command in java and willing to get its result in string variable i have use inetaddress to ping host but my need is to run this command.it is use in "nagios" perhaps it would pe its own command i want to execute this commant in this pattren ??

http://nagios.sourceforge.net/docs/3_0/macros.html
above link is for help

How it would be possible 

Hopes for your suggestions

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无尽的现实 2025-01-02 00:19:00

嗨试试这个代码,

package testapp;

import java.io.DataInputStream;
import java.io.IOException;

/**
 *
 * @author siva
 */
public class TestApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {


        try {
            String ls_str;

            String cmd="check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%";
            String cmd1="/bin/ls -aFl";
            Process ls_proc = Runtime.getRuntime().exec(cmd);

            // get its output (your input) stream

            DataInputStream ls_in = new DataInputStream(
                    ls_proc.getInputStream());

            try {
                while ((ls_str = ls_in.readLine()) != null) {
                    System.out.println(ls_str);
                }
            } catch (IOException e) {
                System.exit(0);
            }
        } catch (IOException e1) {
            System.err.println(e1);
            System.exit(1);
        }

        System.exit(0);

    }
}

Hi Try this code ,

package testapp;

import java.io.DataInputStream;
import java.io.IOException;

/**
 *
 * @author siva
 */
public class TestApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {


        try {
            String ls_str;

            String cmd="check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%";
            String cmd1="/bin/ls -aFl";
            Process ls_proc = Runtime.getRuntime().exec(cmd);

            // get its output (your input) stream

            DataInputStream ls_in = new DataInputStream(
                    ls_proc.getInputStream());

            try {
                while ((ls_str = ls_in.readLine()) != null) {
                    System.out.println(ls_str);
                }
            } catch (IOException e) {
                System.exit(0);
            }
        } catch (IOException e1) {
            System.err.println(e1);
            System.exit(1);
        }

        System.exit(0);

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文