Get terminal process ID on backend

Hey there… I am trying to get the frontend’s currently opened terminal’s process id on the backend, I tried to use TerminalSerivce to get the current terminal and from there the process ID but on launch, I get an error saying

No matching bindings found for serviceIdentifier: Symbol(TerminalService)

I just imported the TerminalService in the backend-with-client-service and injected it as follows:

@inject(TerminalService) protected readonly terminalSerivce: TerminalService;

Is there any step that I missed?

This is what the code looks like after the import statement

return new Promise<string>((resolve, reject) => {
            let term = this.terminalSerivce.currentTerminal;
            term?.processId.then((id) => {
                console.info(`Current terminal acquried`);
                let process = this.processManager.get(id);
                if (process) {
                    process.errorStream.on('data', (data) => {
                        console.info(`Error: ${data}`);
                    })
                }
            });
});

@elvin_arrow sorry for the delay, are you still experience issues?
TerminalService is a frontend service and cannot be used directly in the backend (node).

Yes… no worries about the delay and thanks for the reply @vince-fugnitto .

Yes, I understood that part, and yes I need help figuring that out. What mechanism can I use to get the current terminal’s PID on the back-end as I want to log stdin, stdout, and stderr. My attempt to get the terminal ID using a back-end extension’s terminal-backend-contribution doesn’t really work, although if I do understand correctly, the files in the browser folder point to the front-end instance. When I try calling terminal service in the terminal-backend-contribution residing in the extension’s browser folder, I get the following error on launch:

root WARN Frontend e.configure is slow, took: 422.2 ms
root ERROR Error: No matching bindings found for serviceIdentifier: Symbol(TerminalService)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:18335
    at g (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:18632)
    at e (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:19211)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:19745
    at Array.forEach (<anonymous>)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:19724
    at Array.forEach (<anonymous>)
    at e (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:19271)
    at Object.t.plan (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:19786)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:42:16367
root ERROR Failed to start the frontend application.
root ERROR Error: A command with id 'core.saveAll' does not exist.
    at e.get (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:470640)
    at e.get (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:471073)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:469578
    at Array.sort (<anonymous>)
    at e.addNode (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:469498)
    at e.registerMenuNode (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:467612)
    at e.registerMenuAction (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:467521)
    at e.registerMenus (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:825773)
    at e.onStart (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:467315)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:604788
root INFO Using Git [2.30.0.windows.1] from the PATH. (C:\Program Files\Git\cmd\git.exe)
root ERROR Error: Unknown command with ID: core.save.
    at l (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:88221)
    at e.fillMenuTemplate (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:89101)
    at l (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:87956)
    at e.fillMenuTemplate (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:89101)
    at l (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:87847)
    at e.fillMenuTemplate (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:89101)
    at e.createMenuBar (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:87270)
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:12:87068
    at file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:68442
    at e.invoke (file:///E:/Foundary/Lighthouse/02-Lighthouse-Experimental/lib/bundle.js:1:68661)

I working solely on Theia instance running in electron

If there is any other piece of information required, do let me know :slight_smile:

Thanks…

It fails because like @vince-fugnitto mentioned, you cannot refer to services bound in the browser runtime from the node runtime.

root ERROR Error: No matching bindings found for serviceIdentifier: Symbol(TerminalService)

You should be able to look at the class implementing the TerminalService in the browser runtime, and follow the injected dependencies to their respective proxied services on the backend. Since your extension seem to be implemented mostly in the node runtime, you’ll have to find bound services there.

Quickly looking, a few classes came up: TerminalWatcher, ShellTerminalServer.

Oh… I see I see, I’ll take a look at these classes, thanks :slight_smile:.