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

command always has prefix character "&" #633

Open
QingFengpoor opened this issue May 20, 2021 · 12 comments
Open

command always has prefix character "&" #633

QingFengpoor opened this issue May 20, 2021 · 12 comments
Assignees
Labels

Comments

@QingFengpoor
Copy link

QingFengpoor commented May 20, 2021

Describe the bug
when run commands in Lifecycle or Plugins, it always starts with "&" in terminal. with CMD or BASH, get syntax error, unexpected token &.

Environments (please complete the following information as much as possible):

  • OS: Windows 10
  • VS Code version: 1.56.2
  • Extension version v0.30.1

Screenshots
xxx@xxxx MINGW64 /c/CodeProjects/Java/ReleaseNoteEditor/springmvc/releasenote issue (issue)
$ & mvn compiler:testCompile -f "c:\CodeProjects\Java\ReleaseNoteEditor\springmvc\releasenote issue\pom.xml"
bash: syntax error near unexpected token `&'

@Eskibear
Copy link
Member

function getCommand(cmd: string): string {
if (currentWindowsShell() === ShellType.POWERSHELL) {
return `& ${cmd}`;
} else {
return cmd;
}
}

That's possibly because PowerShell was wrongly detected. What terminal are you actually using? (looks like Git Bash?)
You can check it by command Terminal: Select Default Profile as below
image

@QingFengpoor
Copy link
Author

QingFengpoor commented May 20, 2021

@Eskibear yes, output of Terminal: select Default Profile looks like this

PowerShell C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe                               profiles
Git Bash ...
Command Prompt ...
---------------------------
Windows PowerShell ....                detected
Cygwin ....

the PowerShell profile is highlight.
by default, my terminal is Git Bash. There is something wired that when I open VSCode for this project, the terminal is Powershell, while I add the second terminal, it is Git Bash. For other folders, it is the same. Additionally, when I open the second VSCode window, the terminal is Git Bash.

@QingFengpoor
Copy link
Author

My settings.json contains

    "terminal.integrated.tabs.enabled": true,
    "terminal.integrated.scrollback": 1600,
    "terminal.integrated.defaultProfile.windows": "Git Bash",

only these three conditions for terminal.

@Eskibear
Copy link
Member

"terminal.integrated.defaultProfile.windows": "Git Bash",

I can reproduce your issue by specifying above setting.

In this extension default shell is inferred from vscode.env.shell, defined in https://github.com/microsoft/vscode/blob/2f2b6b528d0062b81d7b3e16c88115827b84cfca/src/vs/vscode.d.ts#L8154-L8159

I believe it's a vscode issue due related to shell profiles.

@Eskibear
Copy link
Member

See microsoft/vscode#121760

@Eskibear Eskibear self-assigned this May 21, 2021
@Eskibear
Copy link
Member

Do you have entry "terminal.integrated.shell.windows" in your settings? If so, remove it. I just tried in latest insiders version, seems it has been fixed.

@QingFengpoor
Copy link
Author

No. I have already noted it.
// "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",.

@QingFengpoor
Copy link
Author

Hi, Eskibear. I think my situation is different from the issue mentioned above.
Firstly, command terminal :select default profile shows the profile of Git Bash.
terminal select default profile

Secondly, I have not use "terminal.integrated.shell.". All terminal settings(containing "terminal") are here:

    // terminal
    "terminal.integrated.tabs.enabled": true,
    "terminal.integrated.scrollback": 1600,
    // "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    // "terminal.integrated.shellArgs.windows": [],
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    // "terminal.integrated.automationShell.windows": "Git Bash",

@Eskibear
Copy link
Member

Root cause is vscode.env.shell doesn't honor what you set in terminal.integrated.defaultProfile. I found similar issues in other popular extensions like python and code runner etc...

It looks vscode team has fixed that (but not released into stable version), and I tried but not repro your issue in latest insiders version. Can you verify if the issue is still there in latest insiders version?
FYI download it here: https://code.visualstudio.com/insiders/

@QingFengpoor
Copy link
Author

Eskibear, I am out off work smile , and my work computer is in my company. I will try it next week. Thank u.

@jaigarV
Copy link

jaigarV commented Jan 17, 2024

The issue is still present in Version: 1.85.1, I have run into it while using Python and a venv. Do you have any idea when will it be released in a stable version of vscode?

@Eskibear Eskibear assigned testforstephen and unassigned Eskibear Jan 17, 2024
@B10inform
Copy link

Hi every one. I cannot see how this issue was resolved. Was it resolved already?
After update to 1.96.4 i am getting these errors.

When i click on Run Python file i get the following error.
(base) @DESKTOP-E49B2GQ:/mnt/d/WSL2/Python/BIOPYTHON$ & D:/PYTHON/python.exe d:/WSL2/Python/BIOPYTHON/ML.py
-bash: syntax error near unexpected token `&'
(base) @DESKTOP-E49B2GQ:/mnt/d/WSL2/Python/BIOPYTHON$

However it works fine with python ML.py

Thank you all for the help

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

No branches or pull requests

5 participants