I setup WSL Ubuntu but I don't know how to connect Code-Runner with WSL.
How to I run code with WSL using Code-Runner?
WSL, of course, uses posix paths (/mnt/c/Users/name/projects) but when Code Runner is used in Windows, all of it's file path variables are windows style (C:\Users\name\projects).
The lastest WSL insider's release has native (except no -h) support for the wslpath command (more here) for converting path types. It can be used with code-runner.executorMap like this:
"code-runner.executorMap": {
"powershell": "powershell.exe $(wslpath -w $fullFileName)",
"bat": "cmd.exe $(wslpath -w $fullFileName)"
}
And to run, for example, a python file in Windows python instead of WSL python:
"code-runner.executorMap": {
"python": "powershell.exe -command \"python $(wslpath -w $fullFileName)\""
}
For now, this works.
In the long term, I expect some more extensible best practices to develop.
But until then, a "wsl": true switch for Code Runner would go a long way. See the Save and Run with wsl plugin.
@garytyler Did you set WSL for the VS Code terminal? If yes, the Code Runner would automatically change the file path. Refer to #106
@formulahendry Yes, I have. I will have a look at #106 and see if I missed anything. Thanks!
@formulahendry, sorry for the delay. It鈥檚 working well now.
Good to know it is working.
@garytyler How did you get it to work? I already have bash set up as my default shell in vscode settings but code runner still tries to run a windows version of node for me
Nvm got it working. Just had to also add:
"code-runner.runInTerminal": true
in addition to
"code-runner.terminalRoot": "/mnt/",
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
Most helpful comment
316 answers how to send commands to wsl, but not how to deal with the file path type problem, which deserves some attention.
The problem
WSL, of course, uses posix paths (/mnt/c/Users/name/projects) but when Code Runner is used in Windows, all of it's file path variables are windows style (C:\Users\name\projects).
Solutions
The lastest WSL insider's release has native (except no -h) support for the
wslpathcommand (more here) for converting path types. It can be used withcode-runner.executorMaplike this:And to run, for example, a python file in Windows python instead of WSL python:
For now, this works.
In the long term, I expect some more extensible best practices to develop.
But until then, a
"wsl": trueswitch for Code Runner would go a long way. See the Save and Run with wsl plugin.