如何在VS Code终端中执行两个命令?

10

我需要在VS Code终端中执行以下命令。我的应用程序在Windows 10机器上运行。

set DEBUG=app & node app.js

当我运行以上命令时,终端会给我以下错误信息。
    At line:1 char:15
   + set DEBUG=app & node app.js
   +               ~
   The ampersand (&) character is not allowed. The & operator is reserved for 
   future use; wrap an ampersand in double quotation marks
   ("&") to pass it as part of a string.
    + CategoryInfo          : ParserError: (:) [], 
      ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed

然而,当我从命令窗口单独运行相同的命令时,它按预期执行良好。
2个回答

16

像这样用;替换&.

set DEBUG=app;node app.js

VSCode 使用 Powershell 作为其终端,在 Powershell 中,命令分隔符是 ; 而不是 &

在此处查看 MSDN 博客

希望这可以帮到你!


1
您可以在 package.json 中创建脚本:
scripts:{
    "start": "set DEBUG=app;node app.js"
}

并使用以下命令运行:
yarn run start // or npm run start (if you use npm)

set 只能在 Windows 上使用,我的建议是使用 cross-env


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接