如何在SOLARIS和HPUX操作系统里调用自己写的java程序,弹出dos窗口(注意要弹出dos窗口),显示ping信息呢?WINDOWS的是"cmd.exe /c start ping 127.0.0.1"
SOLARIS和HPUX这两个操作系统的是什么样的呢?
SOLARIS和HPUX这两个操作系统的是什么样的呢?
解决方案 »
- 编写记事本时怎么样出现鼠标右击的菜单
- java中多个类调用同一个对象是怎么处理
- Eclipse生成的Equals方法和Hashcode方法,与Object的有什么区别?
- 为什么在JDK1.4里正常执行的.class文件,在6.0里却不行?
- 求助,高手帮帮忙!!!
- 请问如何获取屏幕实际大小
- JTable中如何实现表格项的数据验证功能,比如:第一个格子只能填10以下的数,第二个格子只能填20以下的数。。。
- 哪有JAVA电子书呀!
- 如何设置Weblogic中的用户限制,我的Weblogic目前只允许3人登录?
- Junit4使用时出现jdk版本问题,求大神帮忙看一下!!!!
- 我想问下,SOLARIS和HPUX操作系统ping的命令和格式分别是什么?谢谢。
- 我想问下,(在solaris下)如何使用java程序调出dos窗口来实现ping ip的功能?(注意,要弹出dos窗口显示ping信息)。谢谢。
如以下方法,是检测是否ping通服务器的: public static boolean pingServer(String server, long timeout) {
BufferedReader in = null;
Runtime r = Runtime.getRuntime(); String pingCommand = "ping " + server + " -w " + timeout; try {
Process p = r.exec(pingCommand);
if (p == null) {
return false;
}
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
if (line.startsWith("Reply from")) {
return true;
}
}
in.close();
} catch (Exception ex) {
return false;
}
}但是很遗憾的是,只能应用于windows操作系统,solaris无法运行
但是solaris可以如下解决问题:try {
String[] serverArray = server.split("\\.");
byte[] ipByte = new byte[serverArray.length];
for(int i = 0; i < serverArray.length; i++){
ipByte[i] = (byte)Integer.parseInt(serverArray[i]);
}
InetAddress address = InetAddress.getByAddress("" ,ipByte);
return address.isReachable((int)timeout*1000);
} catch (Exception e){
return false;
}
以上是我在项目中的实际经验,希望对楼主有所帮助
如以下方法,是检测是否ping通服务器的: public static boolean pingServer(String server, long timeout) {
BufferedReader in = null;
Runtime r = Runtime.getRuntime(); String pingCommand = "ping " + server + " -w " + timeout; try {
Process p = r.exec(pingCommand);
if (p == null) {
return false;
}
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
if (line.startsWith("Reply from")) {
return true;
}
}
in.close();
} catch (Exception ex) {
return false;
}
}但是很遗憾的是,只能应用于windows操作系统,solaris无法运行
但是solaris可以如下解决问题:try {
String[] serverArray = server.split("\\.");
byte[] ipByte = new byte[serverArray.length];
for(int i = 0; i < serverArray.length; i++){
ipByte[i] = (byte)Integer.parseInt(serverArray[i]);
}
InetAddress address = InetAddress.getByAddress("" ,ipByte);
return address.isReachable((int)timeout*1000);
} catch (Exception e){
return false;
}
以上是我在项目中的实际经验,希望对楼主有所帮助
如以下方法,是检测是否ping通服务器的: public static boolean pingServer(String server, long timeout) {
BufferedReader in = null;
Runtime r = Runtime.getRuntime(); String pingCommand = "ping " + server + " -w " + timeout; try {
Process p = r.exec(pingCommand);
if (p == null) {
return false;
}
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
if (line.startsWith("Reply from")) {
return true;
}
}
in.close();
} catch (Exception ex) {
return false;
}
}但是很遗憾的是,只能应用于windows操作系统,solaris无法运行
但是solaris可以如下解决问题:try {
String[] serverArray = server.split("\\.");
byte[] ipByte = new byte[serverArray.length];
for(int i = 0; i < serverArray.length; i++){
ipByte[i] = (byte)Integer.parseInt(serverArray[i]);
}
InetAddress address = InetAddress.getByAddress("" ,ipByte);
return address.isReachable((int)timeout*1000);
} catch (Exception e){
return false;
}
以上是我在项目中的实际经验,希望对楼主有所帮助
如以下方法,是检测是否ping通服务器的: public static boolean pingServer(String server, long timeout) {
BufferedReader in = null;
Runtime r = Runtime.getRuntime(); String pingCommand = "ping " + server + " -w " + timeout; try {
Process p = r.exec(pingCommand);
if (p == null) {
return false;
}
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
if (line.startsWith("Reply from")) {
return true;
}
}
in.close();
} catch (Exception ex) {
return false;
}
}但是很遗憾的是,只能应用于windows操作系统,solaris无法运行
但是solaris可以如下解决问题:try {
String[] serverArray = server.split("\\.");
byte[] ipByte = new byte[serverArray.length];
for(int i = 0; i < serverArray.length; i++){
ipByte[i] = (byte)Integer.parseInt(serverArray[i]);
}
InetAddress address = InetAddress.getByAddress("" ,ipByte);
return address.isReachable((int)timeout*1000);
} catch (Exception e){
return false;
}
以上是我在项目中的实际经验,希望对楼主有所帮助
如以下方法,是检测是否ping通服务器的: public static boolean pingServer(String server, long timeout) {
BufferedReader in = null;
Runtime r = Runtime.getRuntime(); String pingCommand = "ping " + server + " -w " + timeout; try {
Process p = r.exec(pingCommand);
if (p == null) {
return false;
}
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
if (line.startsWith("Reply from")) {
return true;
}
}
in.close();
} catch (Exception ex) {
return false;
}
}但是很遗憾的是,只能应用于windows操作系统,solaris无法运行
但是solaris可以如下解决问题:try {
String[] serverArray = server.split("\\.");
byte[] ipByte = new byte[serverArray.length];
for(int i = 0; i < serverArray.length; i++){
ipByte[i] = (byte)Integer.parseInt(serverArray[i]);
}
InetAddress address = InetAddress.getByAddress("" ,ipByte);
return address.isReachable((int)timeout*1000);
} catch (Exception e){
return false;
}
以上是我在项目中的实际经验,希望对楼主有所帮助
Runtime.getRuntime().exec("solaris下的ping命令");
那么这个solaris下的ping命令是什么?可不可以这样写?
Runtime.getRuntime().exec("dtterm dtterm -e sh -c start ping -s 127.0.0.1");c++的可以这样写,execlp("dtterm", "dtterm", "-e", "sh", "-c", “ping –s 127.0.0.1“, (char *)0)
那java怎么写?
public class Test
{
public static void main(String[] args) throws Exception
{
Process p = Runtime.getRuntime().exec("/usr/dt/bin/dtterm -e /usr/sbin/ping 127.0.0.1 -n 5");
p.waitFor();
}
}
实现弹出新窗口ping 5次
aix下
public class Test
{
public static void main(String[] args) throws Exception
{
Process p = Runtime.getRuntime().exec("/usr/dt/bin/dtterm -e /etc/ping -c 5 127.0.0.1");
p.waitFor();
}
}
实现弹出新窗口ping 5次。
实在是没有solaris的环境,上面两个都验证过了。
注意dtterm和ping的命令的位置写上绝对路径就可以了
whereis dtterm
which dtterm
这两个命令可以帮你找到它们在哪里