我想从Visual Studio Code运行像MongoDB这样的后台服务。我试图通过任务运行程序来运行它,如下所示:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "mongod",
"isShellCommand": false,
"args": ["--dbpath", "data\\db"],
"showOutput": "always"
}
但这只会在VS内部运行,而无法控制停止服务器,例如通过按Ctrl + C。
正常方法是运行cmd.exe并从那里运行mongod命令。但是我很想将它很好地集成到VS中。
通过将一个命令与子任务一起使用,找到了解决该问题的方法。这将在单独的cmd.exe Shell中运行“ mongod”。一旦启动(在这种情况下,通过/ MIN最小化),我可以通过打开cmd窗口并按ctrl+C正确关闭数据库来停止MongoDB 。
让外壳程序在vscode中运行仍然会更好,但是也许有一天会有更新。
{
"version": "0.1.0",
"command": "start",
"isShellCommand": true,
"showOutput": "never",
"args": [
"/MIN"
],
"tasks": [
{
"taskName": "Start MongoDB",
"args": [
"\"MongoDB @ localhost:27017\"",
"mongod",
"--dbpath",
"${workspaceRoot}/data/db"
],
"suppressTaskName": true
}
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句