Results 1 to 13 of 13
Like Tree4Likes
  • 1 Post By JosAH
  • 1 Post By maca
  • 1 Post By gimbal2
  • 1 Post By JosAH

Thread: program exited with code 0

  1. #1
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default program exited with code 0

    Hi.
    What's wrong with the following program?
    Java Code:
    public class testRuntime{
    	public static void main(String args[]) throws Exception
    	{
    		Runtime.getRuntime().exec("mpstat");
    	}
    }

    I learned that executing mpstat returns information on the CPU.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: program exited with code 0

    ... in *nix operating systems, so if you're running this on Windows then it will fail. And it is likely a shell command so you'd need to execute it through the shell and not directly as you're doing now. To top it off, you're not reading any of its output.

    Mandatory reading: When Runtime.exec() won't | JavaWorld
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: program exited with code 0

    Quote Originally Posted by gimbal2 View Post
    ... in *nix operating systems, so if you're running this on Windows then it will fail. And it is likely a shell command so you'd need to execute it through the shell and not directly as you're doing now. To top it off, you're not reading any of its output.

    Mandatory reading: When Runtime.exec() won't | JavaWorld
    huh, sorry? What should I do?I just need to use the reults of "mpstat"

  4. #4
    maca is offline Member
    Join Date
    Jul 2014
    Location
    UK
    Posts
    16
    Rep Power
    0

    Default Re: program exited with code 0

    Quote Originally Posted by hooshdar3 View Post
    huh, sorry? What should I do?I just need to use the reults of "mpstat"
    If you need the results of mpstat under Windows then you are stuck. Windows does not have the mpstat tool. It's possible that someone somewhere may have ported it, but I would suggest that if you are attempting to write something cross-platform that needs to be able to run on Windows, then parsing the output of mpstat is not the way to do it. Unfortunately I am new to Java so I don't know what (if any) Java libraries are available for CPU statistics interogation.
    Last edited by maca; 07-21-2014 at 11:50 AM.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: program exited with code 0

    Quote Originally Posted by hooshdar3 View Post
    huh, sorry? What should I do?I just need to use the reults of "mpstat"
    If you're running a *nix compatible environment, the mpstat process produces its output on the stderr and/or stdout streams; how do you think your Java program captures those streams? Automagically? The provided link shows you how it can be done, so read it.

    kind regards,

    Jos
    gimbal2 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: program exited with code 0

    Quote Originally Posted by hooshdar3 View Post
    huh, sorry? What should I do?I just need to use the reults of "mpstat"
    Read the article I linked to, and actually learn how to do it properly?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: program exited with code 0

    Quote Originally Posted by gimbal2 View Post
    Read the article I linked to, and actually learn how to do it properly?
    That link doesn't include the worde "mpstat" at all. My problem is not how to execute "runtime.exec()", but about "mpstat" output.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: program exited with code 0

    Good luck with this one guys, I'm going to go cry in a corner.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    hooshdar3 is offline Member
    Join Date
    Jul 2014
    Posts
    28
    Rep Power
    0

    Default Re: program exited with code 0

    Quote Originally Posted by gimbal2 View Post
    Good luck with this one guys, I'm going to go cry in a corner.
    Why?

  10. #10
    maca is offline Member
    Join Date
    Jul 2014
    Location
    UK
    Posts
    16
    Rep Power
    0

    Default Re: program exited with code 0

    Quote Originally Posted by hooshdar3 View Post
    Why?


    I would hazard a guess that the reason why gimbal2 has quite rightly decided to go and cry in a corner is because you clearly haven't read the article. The article explains how to get the output from an exec call (which in your case would be the output of mpstat). It also explains the necessity of reading both input and output streams. Please read the article carefully.

    gimbal2, I just want to say thank you for posting such a great link.
    gimbal2 likes this.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: program exited with code 0

    You are very welcome friend. And you are also very right, although the true reason is that I just feel utter sad that someone is so closed-minded that they -cannot- learn anything even when the information is provided. The first signs of a help vampire:

    The Help Vampire problem - Meta Stack Exchange

    One should avoid becoming one of them.
    maca likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: program exited with code 0

    ... and, if all else fails there's always the <drumroll> <dramatic voice over> rotating knives machine! </dramatic voice over> </drumroll>

    kindest regards,

    Jos

    ps <diabolical laughter/>
    maca likes this.
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: program exited with code 0

    Uh oh, Jos is feeling evil. Even non-spam posts are not safe today! Hide the women and children.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Program Code Help
    By boeschej in forum New To Java
    Replies: 8
    Last Post: 05-11-2013, 05:58 AM
  2. Program won't run need help with code
    By Upcoming in forum New To Java
    Replies: 6
    Last Post: 04-28-2012, 07:56 AM
  3. error code on my program
    By andnlou2678 in forum New To Java
    Replies: 11
    Last Post: 10-12-2011, 12:26 AM
  4. Replies: 2
    Last Post: 04-02-2011, 01:57 PM
  5. What code would you put in a wedding program?
    By frenchzebu in forum Forum Lobby
    Replies: 1
    Last Post: 07-03-2010, 04:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •