Dibyajyoti Behera
Dibyajyoti Behera

Reputation: 171

How I can execute two commands from VS Code Terminal?

I have to execute following command from VS Code Terminal. I am running my application in windows 10 machine.

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.

Upvotes: 11

Views: 4999

Answers (2)

hong4rc
hong4rc

Reputation: 4103

You can create script in 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.

Upvotes: 1

David R
David R

Reputation: 15639

Replace & with ; like this.

set DEBUG=app;node app.js

VSCode uses Powershell as its terminal, And In Powershell the command separator is ; NOT &

Checkout MSDN Blog here

Hope this helps!

Upvotes: 17

Related Questions