

def run(self, config, args):
    server = config.get('server')
    stream = args['--stream']
    if (stream == 'stdin'):
        stream = None
    if ('.' in args['<pid>']):
        (pid, stream) = args['<pid>'].split('.', 1)
    else:
        pid = args['<pid>']
    if (not pid.isdigit()):
        raise RuntimeError('invalid <pid> value')
    try:
        p = server.get_process(int(pid))
    except GafferNotFound:
        print(('process %r not found' % pid))
        return
    if (not stream):
        if (not p.redirect_input):
            raise RuntimeError("can't write on this process, (no stdin)")
    elif (stream not in p.custom_streams):
        raise RuntimeError(('stream %r not found' % stream))
    self.pid = int(pid)
    self.stream = stream
    self.socket = p.socket(mode=pyuv.UV_WRITABLE, stream=stream)
    self.socket.start()
    data = ' '.join(args['<data>'])
    self.args = args
    self.tty = None
    self.should_close = False
    if (data.strip() == '-'):
        self.tty = pyuv.TTY(server.loop, sys.stdin.fileno(), True)
        self.tty.start_read(self._on_tty_read)
        self.sig_handler = SigHandler(self)
        self.sig_handler.start(server.loop)
    else:
        data = data.strip()
        if (not data.endswith('\n')):
            data = (data + os.linesep)
        self.socket.write(data, self._on_done)
    server.loop.run()

dataset/ETHPy150Open benoitc/gaffer/gaffer/cli/commands/send.py Send.run/original