vscode-code-runner: The token '&&' is not a valid statement separator in this version.

  • VS Code Version: 1.35.0
  • OS Version: Windows 10 1903
  • Code Runner Version: 0.9.10

Describe the bug

图片

PS C:\test> cd "c:\test\" && gcc test.c -o test && "c:\test\"test
At line:1 char:15
+ cd "c:\test\" && gcc test.c -o test && "c:\test\"test
+               ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:37
+ cd "c:\test\" && gcc test.c -o test && "c:\test\"test
+                                     ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:40
+ cd "c:\test\" && gcc test.c -o test && "c:\test\"test
+                                        ~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
At line:1 char:50
+ cd "c:\test\" && gcc test.c -o test && "c:\test\"test
+                                                  ~~~~
Unexpected token 'test' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine
 
PS C:\test>

To Reproduce Steps to reproduce the behavior:

Upgrade VSC from 1.34.0 to 1.35.0.


截图没更改execute map;当然改了也是一样的问题。c、c++、c#都有这个问题,所以与语言无关。

宿主机一直可以复现,1.34.0不存在此问题,更新到1.35.0后出现。

我也在我的win7 x86 vm测试了一下,这个问题本来是有的,覆盖1.34.0再覆盖1.35.0后又消失了。

消失是指会用PS的语法,比如&&会被自动替换为分号,会有$?之类的。

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 31 (3 by maintainers)

Most upvoted comments

You just need to change “&&” to “;”

Workaround: add "terminal.integrated.shell.windows": "powershell.exe" to settings

This is a VSC’s feature… See https://github.com/microsoft/vscode-cpptools/issues/3718#issue-450942485

Running this npm config set script-shell command should fix 'The token ‘&&’ is not a valid statement separator in this version" problem.

-Raag!

Tested for Windows 7 / Visual Studio Code version 1.53.2

  1. Search in the following directory for a file “package.json”: C:\Users\Name_of_your_Computer\.vscode\extensions\formulahendry.code-runner-0.11.2 -> first make a copy of the file!
  2. Edit this file using Visual Studio Code. (-> copy the directory path from the Windows-Explorer to the “Open File” )
  3. Go to Line 129, 130 and 131 (about) and change the entries to somthing like that: ( replace all “&&” by “;” - set additional the path ; - remove $dir(before$fileNameWithoutExt) for the last call - and set “artificial” double quotes “…” by \" and … \" - add & .\ in front of the Filename [ & “.\Filename”] ) :

-> The $dir$fileNameWithoutExt command doesn’t work properly! Double quotes (“…”) are placed wrong.

“c”: “cd $dir ; gcc $fileName -o $fileNameWithoutExt ; $Env:PATH += $dir ; & \”.\\$fileNameWithoutExt\“”, “cpp”: “cd $dir ; g++ $fileName -o $fileNameWithoutExt ; $Env:PATH += $dir ; & \”.\\$fileNameWithoutExt\“”, “objective-c”: “cd $dir ; gcc -framework Cocoa $fileName -o $fileNameWithoutExt ;$Env:PATH += $dir ; & \”.\\$fileNameWithoutExt\“”,

  1. Close and restart the program twice (really!! / do it / don’t think about).

Result of the output: Windows PowerShell Copyright © 2009 Microsoft Corporation. Alle Rechte vorbehalten.

PS C:\my_Visual_Studio_Code> cd "c:\my_Visual_Studio_Code\5_hello_CPP" ; g++ 5_helloworld.cpp -o 5_helloworld ; $Env:PATH += "c:\my_Visual_Studio_Code\5_hello_CPP" ; & “.\5_helloworld” - hello world - PS C:\my_Visual_Studio_Code\5_hello_CPP>

You just need to change “&&” to “;”

But where should i change it please tell me i am now in this

Thank you. I’ve settled it. The problem was solved by clicking on “Select the default shell” in “Terminal”.

@imba-tjd that is not the right place to link it. We at the the CppTools extension don’t have anything to do with VS Code’s features. Please file/link issues to their repo at https://github.com/microsoft/vscode/issues