in reply to Re: Parsing 'uptime' output
in thread Parsing 'uptime' output

For example, another way which may prove to be a better alternative for obtaining the uptime would be to source if directly from /proc/uptime (assuming that this interface is available to you)

I understand the sentiment here and often this approach makes sense but I don't think it does in this case.

The output from Solaris's stock uptime is close enough to GNU's that the regex would work without modification. So would IRIX's. And OpenBSD's. None of those systems has a /proc/uptime though. Using the tool in this case is far more portable.

As the uptime program is a stable enough tool that its interface is unlikely to change, using it probably should not be regarded as a maintenance risk either.

Getting your data from another program isn't inherently a bad thing. Nor should it to be shunned in lieu of any alternative. The key is to retrieve your data from an interface that is as stable and portable as possible. In this case, the data source he wanted to use is more standard than the one you suggested.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re3: Parsing 'uptime' output
by blakem (Monsignor) on Aug 19, 2002 at 08:32 UTC

      I read that node and it contains one side of a debate about the merits of using three-argument open over two-argument open. In fact, it is Dominus's reply to tilly's node in which he made the statement that he "would be cautious about suggesting that people use it in any code whose use is meant to be portable."

      It seems to me that tilly and I are actually falling on the same side of completely different debates. I frankly don't even see how that discussion applies to this case and I invite you to enlighten me.

      I think tilly might agree with me if he were still here. Maybe not. I don't know. I wish he was here to speak for himself. Maybe someone should ask Dominus what he thinks as it was his node to which you linked.

      -sauoq
      "My two cents aren't worth a dime.";
      
        Perhaps my one line link could have used a bit more explanation, especially for those who weren't around for the original discussion....

        Two argument open() is badly designed because the second argument actually represents two vastly different types of data (MODE and FILENAME). Getting these two pieces of data from your head to the CPU involves gluing them together and then parsing them apart again. This co-mingled intermediate form is what tilly, Dominus, and Dan Bernstein are warning against.

        In the uptime case, the intermediate form is the english representation of a span of time. If you want your computer to tell you how many seconds its been up, asking it to stringify that information into an english phrase for you to reparse seems like the wrong path to me.

        Given the number of Updates: in this thread, parsing the english is actually somewhat tricky. Why go to all that trouble if your machine can just hand you the exact piece of data you're interested in?

        -Blake