VS Code Open new terminal from powershell

∥☆過路亽.° 提交于 2020-12-05 09:58:17

问题


VS Code (Windows 10)

What I want to achieve from ps1 script :

  • open 4 terminal tabs
  • first one run python venv and then run django server
  • second one run python venv and then run django shell
  • third one run react (yarn start)
  • fourth normal powershell for git and other

I created a powershell script that I run from default opened terminal. Now I'd like to open a new terminal tab from first one.

Can I fire a vs code command shortcut (Ctrl+`) or a vs code command palette (Ctrl+Shift+P) from terminal ?


回答1:


Here is how I solved my problem.

I created a VS Code extension and I used the extension API.

// Create a terminal Window
const term = vscode.window.createTerminal("terminal_name");

// Write any powershell command
term.sendText("cd C:\\path\\to\\follow\\");

// Any other command
term.sendText("yarn start");

// Create a second terminal
const secTerm = vscode.window.createTerminal("second_terminal_name");

secTerm.sendText("cd C:\\another\\path\\to\\follow\\");

secTerm.sendText("py manage.py runserver");

// and so one


来源:https://stackoverflow.com/questions/50983314/vs-code-open-new-terminal-from-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!