Reading the terminal

Re-opening this as a new thread in order to explain the entire scenario…

We are creating a custom IDE currently targeted to support python language and the idea is to fire the bundled language debugger in order to compile and run the programs, and when the debugger finishes execution (or terminates in case of an exception), log everything in the terminal opened by the debugger. The debugger is currently being fire using the CommandService and the following command:

commandService.executeCommand("workbench.action.debug.start")

In order to solve this issue, what comes to mind is maybe listening to the stdin, stdout and stderr streams of the process running the terminal on back-end and for that, implement a back-end extension that allows us to do so since no other mechanism presumably exists to listen to the terminal as entailed by the following existing issue:

The hurdle along the way is to acquire the process ID running that terminal on the backend, because none of the back-end classes support acquiring the process ID. We have tried using the following classes, ShellTerminalServer, TerminalWatcher, ShellProcess but to no avail.

Any suggestions towards the solution of the said issue are highly welcomed… :slight_smile:

P.S. If an end point or API is now available to read the terminal text, kindly do point to that…

How is the terminal spawned precisely? If the debug adapter spawns a raw process, there’s good chances that you won’t be able to read its output. But if the debug adapter spawns a terminal through RunInTerminal then maybe there is a way.

I’d recommend looking around the following code:

The terminal is being spawned by running the following command:

commandService.executeCommand("workbench.action.debug.start")

Which I presume will create a raw process?

Is there a way to tell whether the debugger has finished execution or terminated?

This is a command that starts a debug session. This doesn’t really create a terminal IIUC.

This launches the terminal as well

I have found a temporary solution to my problem, the python’s debugger, I believe it is called debugpy, stores some of its own logs for each execution, so for now I am listening to the callback onDidDestroyDebugSession() on DebugSessionManager.

The logs house the exceptions which is what I was looking forward to log, although, that being said, I would still prefer to read the terminal for our required logs and thus will not mark this as a solution to the problem stated by the thread.

Now that you mention the Python debugger again, I do remember it creating a terminal indeed. It’s part of how the debug adapter works, it runs the whole debugger + debuggee in a client terminal.

Then the code location I sent is worth looking at. This is where requests from the debugger to open a terminal are handled. At this point, you may look at our APIs for ways to intercept that terminal widget and read its output?

Oh okay, I’ll explore that… Thanks :slight_smile: