Ideally, find a stable API which doesn't produce human-readable output which changes between versions and perhaps between locales. On Linux, the /proc
filesystem presents a stable, machine-readable representation of many aspects of system state.
For other things, modern utilities often have an option to produce JSON or other machine-readable output (in the past, XML had a similar role, but it's much less trivial to parse correctly).
If you have to code against a human-readable format like this, try to find stable, reliable test cases and run those on start-up, or perhaps less ideally in a test suite. If you can't get exactly the output you expect, something changed. Of course, your test case needs to be specific and strict enough to actually test all the aspects you care about. (For your example, maybe iwlan lo
is reasonably static and predictable to work everywhere as a test case?)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…