Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:54:11+00:00 2026-05-25T22:54:11+00:00

I am new to mac os. I have used the following code in java

  • 0

I am new to mac os. I have used the following code in java to get the system details. It opens a terminal to display the result of that command. I need to get those details in a file. How can I get it.

String[] command = {"/usr/bin/open", "/Applications/Utilities/System Profiler.app"};
Process proc = Runtime.getRuntime().exec(command);
int resultCode = proc.waitFor();
if (resultCode != 0) {
    throw new Exception("failed to open system profiler");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:54:11+00:00Added an answer on May 25, 2026 at 10:54 pm

    By opening an application to the user, you can not deal with any results. You need to use the commandline-version of the “System Profiler”, which prints it’s results back to the shell.
    You can then deal with the result in Java, by using the following code:

    String[] command = {"/usr/sbin/system_profiler"}
    String sendback = "";    
    Process proc = Runtime.getRuntime().exec(command);
    InputStream istr = proc.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    String str;
    while ((str = br.readLine()) != null) {
        sendback = sendback + str;
    }
    int resultCode = proc.waitFor();
    br.close();
    if (resultCode != 0) {
        throw new Exception("failed to open system profiler");
    }
    

    Within Java, you can deal with the result in any way (write it to a file or whatever).

    But if you really want to simply write it into a file (and not use it in Java), you can do it, by changing your command and redirecting the output into the target-file on your shell:

    /usr/sbin/system_profiler >/path/to/yourfile.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to mac. I have a java project. I created a exe
For my Mac OSX application, I have a feature that removes the system clock
I'm new to Windows development and I have a question. I'm using a Mac
I am using my new mac for the first time today. I am following
I am used to Visual studio, I have class library projects that I reference
Every time I open a new terminal in Mac OSX Lion, rails isn't loaded.
I have the newest XCode (4D199) installed and in terminal when I type new-host-2:
I have some simple OpenGL ES code in C++ that I've run on a
I have used Windows, Mac OS, and Linux (Ubuntu, Redhat). On the Mac OS,
I have a brand new install of Mac OS 10.7.2. I have installed SVN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.