Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
add ability to redirect output (#157)
Browse files Browse the repository at this point in the history
Fixes #60
  • Loading branch information
DonJayamanne authored Mar 1, 2018
1 parent 8555593 commit fa3dc2c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ptvsd/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def __init__(self, socket, pydevd, logfile=None):
self.loop = futures.EventLoop()
self.exceptions_mgr = ExceptionsManager(self)
self.disconnect_request = None
self.launch_arguments = None
self.disconnect_request_event = threading.Event()
pydevd._vscprocessor = self
self._closed = False
Expand Down Expand Up @@ -539,8 +540,17 @@ def on_initialize(self, request, args):
def on_configurationDone(self, request, args):
# TODO: docstring
self.send_response(request)
self.process_launch_arguments()
self.pydevd_request(pydevd_comm.CMD_RUN, '')
self.send_process_event(self.start_reason)

def process_launch_arguments(self):
"""Process the launch arguments to configure the debugger"""
if self.launch_arguments is None:
return

redirect_stdout = 'STDOUT\tSTDERR' if self.launch_arguments.get('redirectOutput', False) == True else ''
self.pydevd_request(pydevd_comm.CMD_REDIRECT_OUTPUT, redirect_stdout)

def on_disconnect(self, request, args):
# TODO: docstring
Expand All @@ -564,6 +574,7 @@ def on_attach(self, request, args):
def on_launch(self, request, args):
# TODO: docstring
self.start_reason = 'launch'
self.launch_arguments = request.get('arguments', None)
self.send_response(request)

def send_process_event(self, start_method):
Expand Down Expand Up @@ -981,6 +992,15 @@ def on_pydevd_send_curr_exception_trace_proceeded(self, seq, args):
except KeyError:
pass

@pydevd_events.handler(pydevd_comm.CMD_WRITE_TO_CONSOLE)
def on_pydevd_cmd_write_to_console2(self, seq, args):
"""Handle console output"""
xml = untangle.parse(args).xml
ctx = xml.io['ctx']
category = 'stdout' if ctx == '1' else 'stderr'
content = unquote(xml.io['s'])
self.send_event('output', category=category, output=content)


########################
# lifecycle
Expand Down

0 comments on commit fa3dc2c

Please sign in to comment.