Don't recursively include the whole stream.h header; only include what's minimally needed, and handle the rest with forward declarations.
The subprocess code was already split into fairly general functions, separate from the Lua code. It's getting pretty big though, especially the Windows-specific parts, so move it into its own files.