Reputation: 991
I made a Mac OS X (native) application that writes one line on STDOUT.
In a Java program, I need to launch that application and get what it writes on the standard output.
The following code works for Windows applications but not for Mac OS X apps.
ProcessBuilder pb = new ProcessBuilder(command);
Process p = pb.start();
p.waitFor();
BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
result = is.readLine();
What am I doing wrong ?
Edit: The command is open -W -n MyApp.app --args myargs
Upvotes: 1
Views: 929
Reputation: 3547
I don't know why it works on Windows honestly. waitFor will wait until the process is done running. At that time stdout from the process does not exist anymore.
You should try switching the waitFor call and the reading of the stream around.
Edit: I don't have a Mac to test that right now but I'm not sure if the open
command actually outputs stdout of the app. You might have to start the binary inside the .app package directly. Most of the time it's something like MyApp.app/Contents/MacOS/myapp args
Upvotes: 2