Implement capture_io for ex_unit

Closes #1035.