Improve cgi process to handle both stdout and stderr