Okay I will try to explain the best I can. I wrote a function in VB that does what I want so I will show you. I am new to Java but I hope this helps.
Function ping(ToLocation as string) as boolean
//Return true if successfull and False if unsuccessfull
Ping = ping(ToLocation)
If not(Ping) then
end
end if
I have also got this code that I am working with, maybe it may help:
try
{
System.out.println("Will attempt to ping " + placeToGo);
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("ping " + placeToGo);
proc.waitFor();
InputStream in = proc.getInputStream();
//Response.Write("You have successfully pinged. ");
System.out.println("You have successfully pinged. ");
return true;
}
catch (Exception e)
{
System.out.println(e.toString());
System.exit(0);
If you know how to do the ping from command line, just place your commands in a command file (example.cmd) and run: cmd.exe is for NT and command.exe is for windows.
Process prcs1 = rt.exec("cmd.exe /c \"example.cmd\"");
try{
prcs1.waitFor();
}
catch(InterruptedException e){
System.out.println("Problem 1");
}
that can work, but I think you'll want to read the output and see if it is successful, something like:
[code]
Process p = Runtime.getRuntime().exec("ping -n 1 -w 5 machine");
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
boolean bSucces = false;
while( (s=r.readLine()) != null) {
if(s.indexOf("(0% ") >= 0) {
bSuccess = true;
}
}
So you are not pinging a harddrive then ;)
But seriously, although this will work on windows, it will not on another platform and the output you get from a command may be different with the language of the windows platform.
that can work, but I think you'll want to read the
output and see if it is successful, something like:
Process p = Runtime.getRuntime().exec("ping -n 1 -w 5
machine");
BufferedReader r = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String s;
boolean bSucces = false;
while( (s=r.readLine()) != null) {
if(s.indexOf("(0% ") >= 0) {
bSuccess = true;
}
}
So you are not pinging a harddrive then ;)
But seriously, although this will work on windows, it
will not on another platform and the output you get
from a command may be different with the language of
the windows platform.
Finally, Are you absolutely sure you need to ping? Can't you just try to connect to this database and see if it fails..
Grasshopper , if you find any good MAC JAVA forums let me know there are lots of little differences that most
JAVA programmers do not know about.(command line?)
I have put in a request for a board , but I don't know if it'll go unheard.
There is nothing (as far as I can remember) in the
MRJ spec for covering datagrams from sockets.
Ping is also quite unreliable as alot of sys-admins don't allow ping requests, and you would have to do it from an app rather than an applet.
maybe it would be worth connecting and if you can't connect (or you time out) then Sytem.exit(0)
hold up...try java.net.DatagramPacket 's send() and recieve() ... don't know if it works , but it sounds alot better than trying to do MS-DOS from a MAC ey?
as I said before if you find a MAC board , give me a shout.
BTW OSX is built atop of BSD , maybe there is some way to use this , Apple are good at supplying information on OSX (but not 8.6 unfortunatly)
hold up... I re-read you're original post
the harddrive? you can't ping you're own hard drive , not even on UNIX... .java.io.file use exists() returns a boolean.... ..
jus remember that on a MAC the seperator is ' : '
and not ' / ' (UNIX) or ' \ ' (MS-DOS)
there is something in JDirect about native File functions
for MAC , if java.io doesn't cut-it , but java.io is simpler.