Re: getting mac address through aglet
In article
<449fa187-854f-48c9-8f8c-f438b5aab658@v20g2000yqm.googlegroups.com>,
moneybhai <manishthe@gmail.com> wrote:
well,this is my code for retrieving the mac address thru aglet2.0.2 .
But the solution is not coming properly.
I don't know about aglets, but your Process has several problems: What
error do you get? Why not read the entire output, which you call "in",
before parsing? Why not check the error stream, too?
Also, please indent your code more readably. It's hard to tell, but your
code may loop forever if no match is forthcoming. Exceptions should
probably be reported to a logger or System.err.
What result do you get from this example?
<code>
import java.io.*;
/** @author John B. Matthews */
class ExecTest {
public static void main (String[] args) {
String s;
try {
Process p = Runtime.getRuntime().exec(
"ipconfig /all");
// read from the process's stdout
BufferedReader stdout = new BufferedReader (
new InputStreamReader(p.getInputStream()));
while ((s = stdout.readLine()) != null) {
System.out.println(s);
}
// read from the process's stderr
BufferedReader stderr = new BufferedReader (
new InputStreamReader(p.getErrorStream()));
while ((s = stderr.readLine()) != null) {
System.err.println(s);
}
p.getInputStream().close();
p.getOutputStream().close();
p.getErrorStream().close();
System.err.println("Exit value: " + p.waitFor());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
</code>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>