Parse output of "net use", but language varies - force language for "net use"?

Bill Stewart bstewart@iname.com
Mon Jul 22 13:52:05 GMT 2024


On Sat, Jul 20, 2024 at 8:57 AM Mark Liam Brown wrote:

Basically I need every bit of information out of "net use", "net
> config", "net statistics", "net view" and so on, parse it in bash or
> perl, process it in bash, and output it in JSON format from the bash
> script for our (Linux-based) admin report interface.
>

The 'net use' command output is not designed for parsing. For example, the
'net user' command outputs usernames in separate columns, and truncates
usernames that are longer than some number of characters (I forget how
many), so it's not a reliable source of truth anyway.

You will need to get the information a different way. As has been
mentioned, on the Windows platform, the best approach would be to use
PowerShell rather than trying to perform parsing on output that's not
designed to be parsed in the first place.

Bill


More information about the Cygwin mailing list