Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The token '&&' is not a valid statement separator in this version. #491

Open
imba-tjd opened this issue Jun 6, 2019 · 31 comments
Open

The token '&&' is not a valid statement separator in this version. #491

imba-tjd opened this issue Jun 6, 2019 · 31 comments

Comments

@imba-tjd
Copy link

imba-tjd commented Jun 6, 2019

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

@imba-tjd imba-tjd changed the title cd "c:\test\" && gcc test.c -o test && "c:\test\"test The token '&&' is not a valid statement separator in this version. Jun 6, 2019
@imba-tjd
Copy link
Author

imba-tjd commented Jun 6, 2019

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

This is a VSC's feature... See microsoft/vscode-cpptools#3718 (comment)

@pieandcakes
Copy link

@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

@imba-tjd
Copy link
Author

imba-tjd commented Jun 6, 2019

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

@pieandcakes
Copy link

Can you update your link to: microsoft/vscode-cpptools#3718 (comment) so its the specific comment?

@imba-tjd
Copy link
Author

imba-tjd commented Jun 6, 2019

🆗

@xiachangsong
Copy link

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

@formulahendry
Copy link
Owner

@xia1065 please refer to https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration

@formulahendry
Copy link
Owner

Let's see whether microsoft/vscode#75091 would be useful

@xiachangsong
Copy link

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

@formulahendry
Copy link
Owner

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

@rohan2017
Copy link

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

@jesusarockias
Copy link

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

Screenshot (1)

@xiachangsong
Copy link

xiachangsong commented Oct 16, 2019 via email

@imba-tjd
Copy link
Author

imba-tjd commented Oct 16, 2019

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.

@NguyenManhCam404
Copy link

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

@mikr13
Copy link

mikr13 commented May 1, 2020

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:- husky@4.2.5 postinstall: "opencollective-postinstall || exit 0"

@Raag007
Copy link

Raag007 commented Jun 1, 2020

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

-Raag!

@awantea106
Copy link

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

@proggdeath
Copy link

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

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

@Satyajit517
Copy link

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

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

@Chruftl
Copy link

Chruftl commented Feb 18, 2021

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>

@sbccas
Copy link

sbccas commented Feb 19, 2021

Worked for me too . Thanks a lot

@hiteshkumawatpro
Copy link

hiteshkumawatpro commented Feb 22, 2021

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.

@SahilKesarwani
Copy link

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.

@atharvabhomle
Copy link

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

@Chruftl
Copy link

Chruftl commented Apr 20, 2021 via email

@larrabasterra
Copy link

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

Thanks a lot!!!

@Dhanushka-Sasanka
Copy link

DONOT USE && and || any more

Try to use

  1. && ==== > -and
  2. | | ===;=> -or

example
( command ) -and ( command )

Like that.

@Satyajit517
Copy link

Satyajit517 commented Aug 24, 2021 via email

@Nguyenducthang1912000
Copy link

I have a better way go to Setting -> terminal and do exactly what i did
image

@gyrao72
Copy link

gyrao72 commented Sep 14, 2021

I have a better way go to Setting -> terminal and do exactly what i did
image

This worked for me
Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests