Hi,
I am not sure if this is the right forum to post this query. However, I really need some expert guidance.
I had done little research for: How to find out the name of the computers that are connected in your network. I was successful in solving this issue. I was able to find those names using :
Process process = Runtime.getRuntime().exec("net view");
After running this command, I use the getInputStream() to extract those name and then I display them.
This works fine on the Windows 2000 Pro. machine. However, when I try to run the same thing on Windows 98, the system seems to hang. I think thats because the output of process.exitValue() is not equal to 0. Is there a different command that I should run for different OS?
I mean is there a different way to launch "net view" command in Windows 98 than in Windows 2000 Pro using Runtime?
I am really confused. Please help.
For everyone's reference, the code that I use is as follows:
StringBuffer strBuffer= new StringBuffer();
String line= null;
try
{
Process process = Runtime.getRuntime().exec("net view");
BufferedReader b = new BufferedReader(new
InputStreamReader(process.getInputStream()));
PrintWriter to= new PrintWriter(process.getOutputStream());
to.close();
try
{
// we need the process to end, else we'll get an
// illegal Thread State Exception
line= b.readLine();
while (line != null)
{
strBuffer.append(line+"\n");
line= b.readLine();
}
process.waitFor();
}
catch (InterruptedException inte)
{
System.out.println("InterruptedException Caught");
}
if (process.exitValue() == 0)
{
System.out.println(strBuffer.toString());
}
process.destroy();
}catch (IOException ioe)
{
System.out.println( "IO Exception Occured While Messing aruond with Processes! -> " + ioe);
}
Thanks,
Riddhi.