Getting the output from a sub-process

A few times recently i’ve needed to capture the output from an OS specific command in Java.   It’s not terribly difficult, but this little example may save you some time.

package test;


public class Main {
    private final static String COMMAND = "/usr/bin/uptime";

    public static void main(String[] args) throws Exception {

       Process process = Runtime.getRuntime().exec(COMMAND);
       BufferedReader stdout =
            new BufferedReader(new InputStreamReader(process.getInputStream()));
       String line = "";
       while ((line=stdout.readLine())!=null) {
       process.waitFor();  // unlikely we'd ever wait as we've got EOF on stdout
       System.out.println("Exit code = "+process.exitValue());

And here is the output as you would expect :

 08:30:47 up 12 days, 23:53,  1 user,  load average: 1.87, 1.99, 2.07
Exit code = 0

openembedded now using git

Ok, so this news is a little old, but nonetheless I am happy to see monotone go.   It made my experience with openembedded less than pleasant.  It was a slow, buggy and outright irritating experience.  Let’s just say – I will happily purge monotone from my systems and never look back.

Thank you Openembedded community, i’m now looking forward to coming back 🙂

It’s sad when…..

For your morning commute you have to walk, catch a bus followed by a train and still more walking to get into the office and it takes about an hour and twenty minutes, costs you $10.10 and then you discover that you can ride into work in One Hour and three minutes, costs you nothing but a little sweat and you have a healthier lifestyle.

Maybe it’s not sad, but perhaps a happy discovery.  People get out of your cars, ignore the pathetic public transport and simply ride to work – the planet will thank you later 🙂