def command_exists(command, noop_invocation, exc_msg):
try:<EOL><INDENT>found = bool(shutil.which(command))  <EOL><DEDENT>except AttributeError:  <EOL><INDENT>try:<EOL><INDENT>p = subprocess.Popen(noop_invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL><DEDENT>except OSError:<EOL><INDENT>found = False<EOL><DEDENT>else:<EOL><INDENT>stdout, stderr = p.communicate()<EOL>found = p.returncode == <NUM_LIT:0><EOL>if not found:<EOL><INDENT>logger.error("<STR_LIT>",<EOL>noop_invocation, p.returncode)<EOL>logger.error("<STR_LIT>", stdout)<EOL>logger.error("<STR_LIT>", stderr)<EOL><DEDENT><DEDENT><DEDENT>if not found:<EOL><INDENT>raise CommandDoesNotExistException(exc_msg)<EOL><DEDENT>return True<EOL>
Verify that the provided command exists. Raise CommandDoesNotExistException in case of an
error or if the command does not exist.

:param command: str, command to check (python 3 only)
:param noop_invocation: list of str, command to check (python 2 only)
:param exc_msg: str, message of exception when command does not exist
:return: bool, True if everything's all right (otherwise exception is thrown)