Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having trouble compiling in VS Code terminal, which is Windows Powershell

When I right click Run code, and have run in terminal on in my user settings I get these errors.

At line:1 char:63
+ ... "c:\Users\Josh\Documents\Programming\Learning to Program\" && g++ Exe ...
+                                                                ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:99
+ ... \Learning to Program\" && g++ Exercise36.cpp -o Exercise36 && "c:\Use ...
+                                                                ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:102
+ ... ercise36 && "c:\Users\Josh\Documents\Programming\Learning to Program\ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
At line:1 char:160
+ ...  "c:\Users\Josh\Documents\Programming\Learning to Program\"Exercise36
+                                                                ~~~~~~~~~~
Unexpected token 'Exercise36' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine

I have been compiling fine up until today, and I did some googling and started typing my own commands into the terminal instead of just running code.

I started replacing the && with -and and get a different problem. This is what the command looks like now.

"c:\Users\Josh\Documents\Programming\Learning to Program\" -and g++ Exercise36.cpp -o Exercise36 -and "c:\Users\Josh\Documents\Programming\Learning to Program\"Exercise36

This is the error I get.

Set-Location : Parameter cannot be processed because the parameter name 'o' is ambiguous. Possible matches include: -OutVariable -OutBuffer.
At line:1 char:87
+ ... \Programming\Learning to Program\" -and g++ Exercise36.cpp -o Exercis ...
+                                                                ~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.SetLocationCommand

I am using the GNU open source compiler, this is the first issue I have had with compiling since I realized you have to save before you compile. I am running a simple string that changes all the characters to X from a string that is read from terminal from C++ Primer program. Any help would be appreciated.

like image 923
XPMJosh Avatar asked Jun 07 '19 05:06

XPMJosh


2 Answers

I had the same problem

PS:

C:\typescript_practice> tsc testclass.ts && node testclass.js

At line:1 char:18 tsc testclass.ts && node testclass.js ~~ The token '&&' is not a valid statement separator in this version. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : InvalidEndOfLine

PS C:\typescript_practice> tsc testclass.ts | node testclass.js Sangamesh Vastrad

worked with below

use | instead of && in latest for node

like image 90
Sangamesh Vastrad Avatar answered Sep 18 '22 01:09

Sangamesh Vastrad


Okay, the problem is that VS Code default terminal is Windows Powershell So you have to change your default terminal to Command Prompt

  1. Click on the Dropdown which shows Powershell besides the + sign for new terminal
  2. Click on Select Default Terminal
  3. You will see options to select from, select Command Prompt

Then those commands will be executable

like image 44
Amogh Bharti Avatar answered Sep 19 '22 01:09

Amogh Bharti