MT#6633 Fix stdout redirection in the daemonize procedure.

(cherry picked from commit 2867a7154d43b02427657381aef226e4010c7fba)