Work around for cwd stat problems with run_command and sudo

This fixes issue #6443