Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run commands in terminal on startup? #3929

Closed
duemaster opened this issue Jan 3, 2019 · 8 comments
Closed

How to run commands in terminal on startup? #3929

duemaster opened this issue Jan 3, 2019 · 8 comments
Labels
question user / developer questions terminal issues related to the terminal

Comments

@duemaster
Copy link

duemaster commented Jan 3, 2019

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

@akosyakov akosyakov added bug bugs found in the application terminal issues related to the terminal labels Jan 3, 2019
@akosyakov
Copy link
Member

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

@duemaster
Copy link
Author

duemaster commented Jan 3, 2019

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

@akosyakov
Copy link
Member

please try to await on terminal.start before calling sendText

@duemaster
Copy link
Author

duemaster commented Jan 4, 2019

@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);

@akosyakov
Copy link
Member

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 akosyakov added question user / developer questions and removed bug bugs found in the application labels Jan 4, 2019
@duemaster
Copy link
Author

@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?

@akosyakov
Copy link
Member

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

@duemaster
Copy link
Author

@akosyakov It works! Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question user / developer questions terminal issues related to the terminal
Projects
None yet
Development

No branches or pull requests

2 participants