Theia: How to run commands in terminal on startup?

Created on 3 Jan 2019  路  8Comments  路  Source: eclipse-theia/theia

I am unable to run terminal commands on startup.

The issue has been discussed here: https://spectrum.chat/theia/general/how-to-run-terminal-commands-on-theia-startup~d6caa472-bd00-4e69-8772-d3e99929c622

question terminal

Most helpful comment

I think it is timing issue again, echo "Test" arrives faster than backend manages to write something to the shell. But one has to investigate, you can try to add some timeout to work it around await new Promise(resolve => setTimeout(resolve, 1000))

All 8 comments

It seems to be a race between opening a connection and calling sendText.

@akosyakov Is there an alternative way which I can achieve the same goal while avoiding this race condition?

please try to await on terminal.start before calling sendText

@akosyakov I tried sendText and it does display the command on the terminal. However, it still requires me to press enter manually to execute the command. Is this the expected behaviour?

The flow now is like this:

                let terminalWidget = await this.terminalService.newTerminal({});
                await terminalWidget.start();
                await terminalWidget.sendText("ls -all")
                await this.terminalService.activateTerminal(terminalWidget);

yes, I think it is expected

sendText under the hood just sending characters to the backend shell. Have you tried to prepend \r\n? :)

@akosyakov Thanks for the solution! It works. However, there seems to be a small issue.

The command to be ran appear on top of the terminal.
screenshot from 2019-01-04 17-18-24

Rather than
screenshot from 2019-01-04 17-20-42

This is the code that triggers it:

                let terminalWidget = await this.terminalService.newTerminal({});
                await terminalWidget.start();
                await terminalWidget.sendText('echo "Test"\n')
                await this.terminalService.activateTerminal(terminalWidget);

Is there something that I am missing?

I think it is timing issue again, echo "Test" arrives faster than backend manages to write something to the shell. But one has to investigate, you can try to add some timeout to work it around await new Promise(resolve => setTimeout(resolve, 1000))

@akosyakov It works! Thanks for the help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fangnx picture fangnx  路  3Comments

akosyakov picture akosyakov  路  3Comments

jankeromnes picture jankeromnes  路  3Comments

Beetix picture Beetix  路  3Comments

akosyakov picture akosyakov  路  3Comments