def command(*commands, **kwargs):
    commands = list(commands)
    if 'stdout' in kwargs:
        commands[-1] += ' >"{0}"'.format(kwargs['stdout'])
    if 'stdin' in kwargs:
        stdin = (kwargs['stdin'].replace(u'\\', u'\\\\').
                                 replace(u'$', u'\\$').
                                 replace(u'`', u'\\`'))
        if kwargs.get('escape_stdin', False):
            stdin = stdin.replace(u'{', u'{{').replace(u'}', u'}}')
        eof = 'EOF'
        while eof in stdin:
            eof += 'EOF'
        commands[0] += ' <<{0}'.format(eof)
        return ''.join([' | '.join(commands).format(*kwargs.get('args', ())),
                        '\n',
                        stdin,
                        '' if '' == stdin or '\n' == stdin[-1] else '\n',
                        eof])
    return ' | '.join(commands).format(*kwargs.get('args', ()))
dataset/ETHPy150Open devstructure/blueprint/blueprint/frontend/sh.py/command/original