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

Created on 6 Jun 2019  ·  27Comments  ·  Source: formulahendry/vscode-code-runner

  • 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的语法,比如&&会被自动替换为分号,会有$?之类的。

bug upstream

Most helpful comment

You just need to change "&&" to ";"

All 27 comments

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

@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

@pieandcakes I know, but I just want the notice and that 2 more links which Tyriar mentioned. 😄

Can you update your link to: https://github.com/microsoft/vscode-cpptools/issues/3718#issue-450942485 so its the specific comment?

🆗

I'm weak. I still don't know how to solve this problem.

Let's see whether https://github.com/microsoft/vscode/issues/75091 would be useful

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

Have a workaround fix for this issue.
Waiting for VS Code API for a better resolution.

I am having the same issue right now. How exactly did you fix it

I am having the same issue right now. How exactly did you fix it

Screenshot (1)

I remember adjusting that PowerShell in my  circle.emm..  you can have try to change optiona.

---Original---
From: "jesusarockias"<[email protected]>
Date: Wed, Oct 16, 2019 18:07 PM
To: "formulahendry/vscode-code-runner"<[email protected]>;
Cc: "xiachangsong"<[email protected]>;"Mention"<[email protected]>;
Subject: Re: [formulahendry/vscode-code-runner] The token '&&' is not a valid statement separator in this version. (#491)

I am having the same issue right now. How exactly did you fix it


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

For now you don't need to change anything. So you two probably not have the same issue as this one.

But you can always use the "shell-specific" command.

You just need to change "&&" to ";"

You just need to change "&&" to ";"

Yeah but that doesn't solve the problem if an npm package calls that command, right?
For ex.: husky postinstall:- [email protected] postinstall: "opencollective-postinstall || exit 0"

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

-Raag!

You must use CMD default Windows. cant with VSC or GIT bash

You just need to change "&&" to ";"

This solve my problem.
Thanks a lot ! 👯‍♂️

You just need to change "&&" to ";"

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

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 (C) 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>

Worked for me too . Thanks a lot

This problem can be fixed by following few steps:

1) Open Terminal
2) Select----SELECT DEFAULT SHELL---option provided in menu list type option on the right-hand side.
3) Select -- COMMAND PROMPT---CMD.EXE

then run the code again and enjoy.

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 (C) 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>

Thanks a lot bro. Literally man you nailed it...Thanks again.

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 (C) 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>

i encountered same problem but in your first step the file you have referring is folder as i can see. I hve attached SS now tell me what to do?
Screenshot_1

Hello,

 

sees you have a newer Version of the coderunner.  (......code-runner-0.11.2    ->    ...... code-runner-0.11.3)

 

So open the directory that you marked and continue as discribed.

 

C. Baumeister

 
 

Gesendet: Dienstag, 20. April 2021 um 19:27 Uhr
Von: "atharvabhomle" @.>
An: "formulahendry/vscode-code-runner" *
@.>
Cc: "Chruftl"
@.>, "Comment" @.*>
Betreff: Re: [formulahendry/vscode-code-runner] The token '&&' is not a valid statement separator in this version. (#491)

 

Tested for Windows 7 / Visual Studio Code version 1.53.2

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!
Edit this file using Visual Studio Code. (-> copy the directory path from the Windows-Explorer to the "Open File" )
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"",

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

Result of the output:
Windows PowerShell
Copyright (C) 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>

i encountered same problem but in your first step the file you have referring is folder as i can see. I hve attached SS now tell me what to do?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

You just need to change "&&" to ";"

Thanks a lot!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

N2ITN picture N2ITN  ·  5Comments

nmchgx picture nmchgx  ·  3Comments

Salil03 picture Salil03  ·  5Comments

mjaniec2013 picture mjaniec2013  ·  5Comments

Yensan picture Yensan  ·  4Comments