1

I am developing an extension for Visual Studio Code. I need to open a terminal window and run some command there (One after another finishes). Same as Terminal.sendText but not in integrated terminal. Is there a way to do that?

Update

The closest I've got is using:

const childProcess = spawn('node', ['--version'],{
    shell: true,
    detached: true,
    windowsHide: false
});

And the problem is it closes automatically

Saad
  • 36
  • 5
  • If you wan't to run multiple commands inline, you can use `&` symbol, like `echo yes & echo no` and if you wan't the next one only to run if the first one successful you can use `&&` – Harry Kruger Jan 27 '21 at 06:19

1 Answers1

0

You could possibly run the machine's terminal application and specify a command to run, like with mate-terminal, -e option. You could then run bash with certain startup commands How to invoke bash, run commands inside the new shell, and then give control back to user?

Harry Kruger
  • 187
  • 1
  • 12
  • A example of that might be `mate-terminal -e "bash -c \"bash --rcfile <(echo '. ~/.bashrc; ping google.com')\""` it's pretty crude, but I think you understand what I mean. it's just hard because there is a lot of terminal programs out there with different flags – Harry Kruger Jan 26 '21 at 18:54
  • Umm, sorry I can't understand this clearly. Run this command in the integrated terminal? And vscode extension can be used in all operating systems, what'll be the solution for those? – Saad Jan 26 '21 at 19:16
  • what part don't you understand? you will need to execute this command, also im not very sure of any command that's cross platform that runs a specific command in terminal, you will just need to add support for all the platforms manually. I know of `x-terminal-emulator` for debain that runs the default terminal application and takes a -e flag too. – Harry Kruger Jan 26 '21 at 19:31
  • Actually I expected if vscode extension api provides some function to make the task easier. And I've updated the question. – Saad Jan 26 '21 at 21:01
  • I would not think so, this is quite a random thing. but I have not used the vscode extension api before so I am not sure. – Harry Kruger Jan 26 '21 at 21:03
  • I took a quick glance over the vscode api and I saw nothing about opening a external terminal. why would you need this btw? – Harry Kruger Jan 26 '21 at 21:08
  • I know of a sublime extension https://github.com/wbond/sublime_terminal/ that can open a terminal in almost any os, so it is certainly possible, and I found this module that has support for quite a few operating systems https://www.npmjs.com/package/open-term – Harry Kruger Jan 27 '21 at 06:33