Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Weird Issue in Getting Mac Address

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Weird Issue in Getting Mac Address

    I'm using Eclipse in Windows 7, 64-bit. I have some pretty standard code that does this:

    BufferedInputStream bi;

    try {
    // WINDOWS VERSION
    if (System.getProperty("os.name", "Windows").startsWith("Windows")) {

    bi = new BufferedInputStream(Runtime.getRuntime().exec("ipc onfig -all").getInputStream());
    bi.read(buff);
    String ipConfig = new String(buff);


    ....etc. (I go into the String and get the "Physical Address" strings.)

    When I step through this code line-by-line in debug mode, it works fine and gets the Mac address.

    When I run it in non-debug mode (i.e., without stepping through) it only manages to get these first two lines of the complete ipconfig:

    Windows IP Configuration

    Host Name . . . . . . . . . . . . : Robo

    So, I can't get my machine's Mac address with this code. It's very strange. Why does the code work when stepping through but not in a regular run?

    Can anyone give me any help?


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Weird Issue in Getting Mac Address

    I must find a way to convert buffering questions into money... That's not begging, I'm not that desperate - yet

    You're reading a *buffered* stream. Something puts data into the buffer and you take it out. The rates are different. When you step through, the thing putting data into the stream has plenty of time to finish filling it up. When you run it without pausing, you say "OK, here's the buffer, start fillin...I-read-it-all-NOW!", and you only get the little bit the source has managed to put into the buffer.

    You either need to poll the buffer, wait for an agreed 'END OF TRANSMISSION' token, or use a class that does exactly what you need - like BufferedReader and its readLine() method.

  3. The Following 3 Users Say Thank You to Sean4u For This Useful Post:

    Jim Ryan (August 30th, 2011), KevinWorkman (August 30th, 2011), Tjstretch (August 30th, 2011)

  4. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Weird Issue in Getting Mac Address

    Thanks, Sean4u. That's a great lesson on buffering. I'll give it a try and post back with the results...

  5. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Weird Issue in Getting Mac Address

    Lol I thanked for my friend.. I was trying to explain buffered streams and he didn't get it. Now he does, Thanks!

  6. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Weird Issue in Getting Mac Address

    Yes, it works, thanks again.

    I don't know how to poll a buffer so I used BufferedReader.readLine(). Works like a charm!

    By the way, my co-worker says that the original (flawed) code used to work on some slower machines. My machine has an i5 chip - pretty fast. Perhaps this chip's speed has caused the issue to show up?

    Anyway, thanks again!

  7. #6
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Weird Issue in Getting Mac Address

    the original (flawed) code used to work on some slower machines
    Haha that's nice to hear. It could be anything - perhaps even multi-threading (a change in your JVM?) or multi-processing - allowing the starting context to resume faster / earlier than it once did. I'm glad you got it working.

Similar Threads

  1. VERY WEIRD OUTPUT... HELP PLEASE?
    By Medo Almasry in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 23rd, 2011, 10:02 AM
  2. ClassNotFoundException (bit weird)
    By chronoz13 in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 02:15 AM
  3. [SOLVED] Weird calendar.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 3rd, 2011, 08:19 PM
  4. Jsp weird problem
    By johniem in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 5th, 2010, 06:46 AM
  5. Weird issue with while loop ending/being skipped
    By ang3c0 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 25th, 2009, 12:09 PM