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
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.

Rather than

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!
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 aroundawait new Promise(resolve => setTimeout(resolve, 1000))