added execAndWriteOutput