3 ms·
The thing is, you can never predict which command outputs you're going to need to consume programatically. Even if you have control over the codebase, it might
by angdis 15y ago
The thing is, you can never predict which command outputs you're going to need to consume programatically. Even if you have control over the codebase, it might not be desirable because of time-burn to make it so that your commandline outputs in a uniform machine-readable way.
I think another approach is to use robust, good tools to parse human readable output (assuming it is reasonably consistent as many unix commands are, for instance).
There is a great tool for TCL environments called "Expect". You can use that to send/parse commmands in the shell or ssh, ftp, even over serial ports, etc. There are sophisticated capabilities for regex-based matching, and the syntax is nicely compact. There are also ways to fork tasks so that multiple command/response sessions can be done in parallel.
I really wish that something like "Expect" existed in .NET or Java. It was nice to have it as a tool.