Add an error handling on stdin.write