0

i'm trying to get a list of MAC addresses of available wifi networks with java .

i have found a command line that returns a perfect result

netsh wlan show networks mode=Bssid | findstr "BSSID"

but when executing this command with Runtime().getRuntime().exec() i'm getting error and the

program prints the command's help

what am i doing wrong ??

try {
        String command="netsh wlan show networks mode=Bssid | findstr \"BSSID\"";

        InputStream input = Runtime.getRuntime().exec(command).getInputStream();

        InputStreamReader reader = new InputStreamReader(input);

        BufferedReader buffer = new BufferedReader(reader);
        String line="";

        while((line=buffer.readLine()) != null ){
            System.out.println(line);
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
hannibal
  • 266
  • 4
  • 15
  • possible duplicate of [java runtime.getRuntime.exec( cmd ) with long parameters](http://stackoverflow.com/questions/6434009/java-runtime-getruntime-exec-cmd-with-long-parameters) – maksimov May 01 '14 at 17:53
  • Also you can do filtering in Java. And also this is not portable. – maksimov May 01 '14 at 17:54
  • Possible duplicate of http://stackoverflow.com/questions/5928225/how-to-make-pipes-work-with-runtime-exec – cangrejo May 01 '14 at 17:55
  • i have just tried the solution but not working – hannibal May 01 '14 at 18:11
  • i have found the problem !! it's the pipe how can i manage this ? – hannibal May 01 '14 at 19:36
  • 1
    You can't. Pipe is part of the shell interpreter, not the JVM. You could try the answer discussed here though (broncoAbierto posted it further up). http://stackoverflow.com/questions/5928225/how-to-make-pipes-work-with-runtime-exec – Ryan J May 01 '14 at 19:40

0 Answers0