This module comes from the nth time I've had to implement a select loop and wanted appropriate sudo/su privilege magic, environment variables that are set in the child, working directories set etc.

It aims to provide a reasonable interface for setting up command execution environment (working directory, environment variables, stdin, stdout and stderr redirection if necessary), but allowing for ssh and sudo and magicing in the appropriate shell quoting.

It tries to be flexible about how you might want to capture output, exit status and other such, but in such a way as it's hopefully easy to understand and make it work.

This is expected to generate the text to send to stdin. It is called with an argument of the number of bytes that the caller wants to read. If it generates more, some may be lost - you have been warned.

The 2 argument form takes a type and then a ref, handle or other. Valid types: