Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

To integrate with other executables, a executable may launch another executable and capture its output from stdout.

But most programs writes the output message to stdout in custom format and usually in human readable format.

So it requires the system integrator to write a function to parse the output, which is considered trouble and the parser code may be buggy.

Do you think this is old fashioned? Most Unix-style programs do that.

Very few programs write to stdout in standard format such as XML or JSON, which is more modern. Example: Veracity (DVCS) writes JSON to stdout.

Should we switch to use modern formats? For a console program, human readable or easy parsable: which is more important ?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Not trying to sound crotchety here, but one line per record, with fields in columns or delimited so they can be easily parsed by cut without writing custom code, is a standard format, and was a deliberate design decision. Read Eric S. Raymond's The Art of Unix Programming sometime. It will increase your appreciation for innovations that we now take for granted, and has whole chapters on the importance of output that is easily human readable. A format still being around and widely used after 40 years is a sign of its strength, not its weakness.

A common approach is to use command line flags to make an output format that is easy for both humans and computers to parse. Look at the git porcelain output formats for a good example.

One situation where xml or json is recommended, however, is when your data is arbitrarily nested instead of something easily put into rows. That determination should be made on a case by case basis. Xml is better than binary formats, but still not as readable as a plain text table.

share|improve this answer
    
+1 for git porcelain –  Eddie B Nov 17 '12 at 19:18
    
what about JSON? lightweight than XML –  linquize Nov 18 '12 at 0:59
    
human readable but does not escape special characters. We cannot assume that there is no special characters. For XML/JSON, must escape special characters –  linquize Jan 23 '13 at 5:17
add comment

Parsing any form of output can be buggy. Just because the output format follows a specific format does not guarantee correct semantics. If you have the source for the executables, you can change the output into whatever format you desire. If you do not, but the executable otherwise meets your needs, you suck it up and parse the output.

share|improve this answer
    
You don't need to parse XML or JSON yourself. There are ready-made parser libraries. –  linquize Nov 18 '12 at 6:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.