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");
}
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:
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: