Fix bugs. TODO: chdir in exec does not work it is launched in a thread.