<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sos_get_command_output(command, timeout=300, stderr=False, chroot=None, chdir=None, env=None, binary=False, sizelimit=None, poller=None):
 """Execute a command and return a dictionary of status and output, optionally changing root or current working directory before executing command. """

    # Change root or cwd for child only. Exceptions in the prexec_fn
    # closure are caught in the parent (chroot and chdir are bound from
    # the enclosing scope).
    def _child_prep_fn():
        if (chroot):
            os.chroot(chroot)
        if (chdir):
            os.chdir(chdir)

    cmd_env = os.environ.copy()
    # ensure consistent locale for collected command output
    cmd_env['LC_ALL'] = 'C'
    # optionally add an environment change for the command
    if env:
        for key, value in env.items():
            if value:
                cmd_env[key] = value
            else:
                cmd_env.pop(key, None)
    # use /usr/bin/timeout to implement a timeout
    if timeout and is_executable("timeout"):
        command = "timeout %ds %s" % (timeout, command)

    # shlex.split() reacts badly to unicode on older python runtimes.
    if not six.PY3:
        command = command.encode('utf-8', 'ignore')
    args = shlex.split(command)
    # Expand arguments that are wildcard paths.
    expanded_args = []
    for arg in args:
        expanded_arg = glob.glob(arg)
        if expanded_arg:
            expanded_args.extend(expanded_arg)
        else:
            expanded_args.append(arg)
    try:
        p = Popen(expanded_args, shell=False, stdout=PIPE,
                  stderr=STDOUT if stderr else PIPE,
                  bufsize=-1, env=cmd_env, close_fds=True,
                  preexec_fn=_child_prep_fn)

        reader = AsyncReader(p.stdout, sizelimit, binary)
        if poller:
            while reader.running:
                if poller():
                    p.terminate()
                    raise SoSTimeoutError
        stdout = reader.get_contents()
        while p.poll() is None:
            pass

    except OSError as e:
        if e.errno == errno.ENOENT:
            return {'status': 127, 'output': ""}
        else:
            raise e

    if p.returncode == 126 or p.returncode == 127:
        stdout = six.binary_type(b"")

    return {
        'status': p.returncode,
        'output': stdout
    }