嗨,我正在使用linux,并尝试在java中执行此命令,并愿意在字符串变量中获取其结果,我已经使用inetaddress来ping主机,但我需要运行此命令。它在“nagios”中使用,也许它会pe它自己的命令,我想在这个pattren中执行此命令?
http://nagios.sourceforge.net/docs/3_0/macros.html 上面的链接是为了寻求帮助
How it would be possible
希望得到您的建议
提前致谢
最佳答案
嗨,试试这个代码,
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);
}
}
关于java - 如何从 Java 代码运行此命令 "check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8814560/