Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 694
Dibyajyoti Behera Avatar asked Jul 18 '18 12:07

Dibyajyoti Behera


People also ask

How do I run multiple commands in VS Code?

You can always mark your 2 most common commands with isBuildCommand and isTestCommand to run them via cmd + shift + b or cmd + shift + t respectively. This answer has some helpful information that might be useful to you as well.

How do I switch between two terminals in VS Code?

Once the cursor is in the terminal section you can use ctrl+x ctrl+up or ctrl+x ctrl+down to cycle through the active terminals (note that moving between on-screen split terminals is done with ctrl+x left or ctrl+x right ). cmd-J is still used to hide/show the terminal pane.


Video Answer


2 Answers

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!

like image 91
David R Avatar answered Sep 27 '22 18:09

David R


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.

like image 41
hong4rc Avatar answered Sep 27 '22 17:09

hong4rc