如何从VS Code Terminal执行两个命令?

时间:2018-07-18 12:20:28

标签: node.js visual-studio-code

我必须从VS Code Terminal执行以下命令。我正在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 个答案:

答案 0 :(得分:3)

&替换为;

set DEBUG=app;node app.js

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

Checkout MSDN Blog here

希望这会有所帮助!

答案 1 :(得分:1)

您可以在package.json中创建脚本:

scripts:{
    "start": "set DEBUG=app;node app.js"
}

并运行以下命令:

yarn run start // or npm run start (if you use npm)

set只能用于窗口,我的建议是使用cross-env

相关问题