<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def pandoc(args, filein=None, fileout=None):
 """Execute pandoc with the given arguments"""

    cmd = [u'pandoc']

    if filein:
        cmd.append(filein)

    if fileout:
        cmd.append('-o')
        cmd.append(fileout)

    cmd.extend(args.split())

    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    out, err = proc.communicate()
    if proc.returncode:
        raise PandocError('pandoc exited with return code {}\n{}'.format(proc.returncode, str(err)))
    return out.decode('utf-8')