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

Bash on Windows10 issue #106

Closed
VincentFrangi opened this issue Apr 19, 2017 · 17 comments
Closed

Bash on Windows10 issue #106

VincentFrangi opened this issue Apr 19, 2017 · 17 comments

Comments

@VincentFrangi
Copy link

VincentFrangi commented Apr 19, 2017

I'm working on a python project using bash on Windows10 as terminal
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe",

I use the integrated terminal with code-runner
"code-runner.runInTerminal": true,

When I run the code, the following command is launch :
python3.6 "d:\HES\Semestre_6\Projet_linux\TelePyDuino_Monitoring\Python\bot3.py"
Python can't open file because there is no such file or directory
This is a windows path..

The command with the right path for bash has to be :
python3.6 /mnt/d/HES/Semestre_6/Projet_linux/TelePyDuino_Monitoring/Python/bot3.py

Is there sometting in the settings ?
Could you fix it

thanks,
Vincent

@kongroo
Copy link

kongroo commented Apr 19, 2017

The same issue. The $filename variable returns a windows style path, it shouldn't be hard to detect if bash on windows is used and map a windows path to a shell path.

@formulahendry
Copy link
Owner

@kongroo PR is welcome! 😃

@formulahendry
Copy link
Owner

This issue has been fixed, please try the latest version.

@leongwaikay
Copy link
Contributor

Because Windows filesystem is not case sensitive, my setting was "terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\bash.exe",, which caused the new fix to not work.

@leongwaikay
Copy link
Contributor

The default executor for C/C++ is cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt". Only the first $dir is being replaced. The second $dir still expands to the Windows style path.

formulahendry added a commit that referenced this issue Jul 22, 2017
@formulahendry
Copy link
Owner

Thanks @pottiepie ! Those two issues has been fixed. Please try the latest version.

@leongwaikay
Copy link
Contributor

Thanks @formulahendry. It works great now. Though I felt it might be better to do the path replacement in getCodeFileDir instead since this (I think) would replace the entire exec string.

@formulahendry
Copy link
Owner

Thanks @pottiepie for your suggestion. I will consider improving this.

@djtorel
Copy link

djtorel commented Jul 27, 2017

Hello, would it be possible to make this fix work for other types of bash shells being used in Windows, like Cmder, Git Bash/Mintty, Cygwin? Perhaps it could use the "terminal.integrated.shell.windows" setting as reference for where the variables should be run from? I have the same issue and was using: "terminal.integrated.shell.windows": "C:\Program Files\Git\bin\bash.exe" for example.

@formulahendry
Copy link
Owner

@djtorel , #149 is opened to track it.
The most tricky part is the Windows Drive path in each bash is different.

  • Bash on Windows: it is /mnt/c/...
  • Git Bash: it its/c/..
  • And for other bash, it seems also different.

Do you know the Windows Drive path format for Cmder, Git Bash/Mintty, Cygwin, MinGW or others?

@djtorel
Copy link

djtorel commented Jul 28, 2017

Thanks for responding! Cmder uses git bash and Mintty as bash options by default and of course cmd and powershell. I apologize for bringing that up specifically, because I don't think it can integrate with VSCode's terminal (it's basically a configuration ConEmu).

Both Git Bash and Mintty have /c/...
Cygwin is /cygdrive/c/...

@leongwaikay
Copy link
Contributor

leongwaikay commented Jul 28, 2017 via email

@formulahendry
Copy link
Owner

@djtorel , I have tried running code in Git Bash without issue:
image
It seems that it could handle Windows file path well. Could you please let me know what issue you meet with?

@leongwaikay
Copy link
Contributor

I've submitted a pull request to basically allow user to customize whichever terminal root they want. Problem with Cygwin is that user could have installed it in another directory with "Windows" in the path and it also runs bash.exe, which currently the code takes to be Bash on Ubuntu.

@JUD210
Copy link

JUD210 commented Apr 25, 2019

@djtorel , I have tried running code in Git Bash without issue:
image
It seems that it could handle Windows file path well. Could you please let me know what issue you meet with?

Languages using '$dir' value in "code-runner.executorMap" is not working because the format of "$dir" value is not for Git Bash.

Refer code-runner.executorMap,

"python": "python -u",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",

if (your code runner runs in integrated terimal && your terminal is git bash)
{
python is working in any workspace internal folder
cpp / java is not working in any directory
}

issue

@JamesQian1999
Copy link

I also setup WSL Ubuntu but I can't run with WSL in right the path.
How to I run code with WSL in the right path?

This is my settings.json
{ "code-runner.runInTerminal": true, "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe", "code-runner.executorMap": { "c": "cd $(wslpath $dir) & gcc $fileName -o $fileNameWithoutExt & ./$fileNameWithoutExt", "cpp": "g++ $fileName -o $fileNameWithoutExt -std=c++11 & ./$fileNameWithoutExt"}, "python": "python3 -u ./$fileName", }

When I run my code with "ctrl+alt+N"
The output became:
jamesqian@J:/mnt/c/Users/Jamesqian/Desktop/tmp$ cd $(wslpath "c:\Users\Jamesqian\Desktop\tmp\") & gcc test.c -o test & ./test

wslpath is https://github.com/laurent22/wslpath

@asukaminato0721
Copy link

Solution: #468 (comment)

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

8 participants