简体   繁体   English

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

[英]How I can execute two commands from VS Code Terminal?

I have to execute following command from VS Code Terminal. 我必须从VS Code Terminal执行以下命令。 I am running my application in windows 10 machine. 我在Windows 10计算机上运行我的应用程序。

set DEBUG=app & node app.js

when I run the above command the terminal gives me following error message. 当我运行上述命令时,终端会显示以下错误消息。

    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

However when I run the same command from command window separately it executes fine as expected. 但是,当我从命令窗口分别运行同一命令时,它按预期执行得很好。 Please help me solve this. 请帮我解决这个问题。

Thanks in advance. 提前致谢。

Replace & with ; 用替换& ; like this. 像这样。

set DEBUG=app;node app.js

VSCode uses Powershell as its terminal, And In Powershell the command separator is ; VSCode使用Powershell作为其终端,而在Powershell ,命令分隔符为; NOT & &

Checkout MSDN Blog here 在此处签出MSDN博客

Hope this helps! 希望这可以帮助!

You can create script in package.json : 您可以在package.json创建脚本:

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

and run with command: 并使用命令运行:

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

set just can use for window, my suggest is use cross-env . set只能用于窗口,我的建议是使用cross-env

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM