<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def execute_code_block(elem, doc):
 """Executes a code block by passing it to the executor. Args: elem The AST element. doc The document. Returns: The output of the command. """

    command = select_executor(elem, doc).split(' ')
    code = elem.text
    if 'plt' in elem.attributes or 'plt' in elem.classes:
        code = save_plot(code, elem)
    command.append(code)
    if 'args' in elem.attributes:
        for arg in elem.attributes['args'].split():
            command.append(arg)

    cwd = elem.attributes['wd'] if 'wd' in elem.attributes else None

    return subprocess.run(command,
                          encoding='utf8',
                          stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT,
                          cwd=cwd).stdout