formulahendry / vscode-code-runner

Code Runner for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
MIT License
2.21k stars 298 forks source link

about "code-runner.fileDirectoryAsCwd" #571

Open asasn opened 4 years ago

asasn commented 4 years ago

当我使用setting.json配置了terminal "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe","code-runner.fileDirectoryAsCwd": true, 它就会使用如下命令跳转目录 cd xxx/xxx 然而cmd.exe的命令"cd",缺少参数"/d",将无法进入到相应目录。 它似乎是和"code-runner.cwd"配合使用的,不知道这是一个bug还是原意如此? 目前我是在"code-runner.executorMap"里面自行配置相应语言的配置,在开头加入cd /d $dir —————————————————————————————— When I configured the terminal using setting.json " terminal.integrated.shell.windows ":" C: \\ WINDOWS \\ System32 \\ cmd.exe ", with "code-runner.fileDirectoryAsCwd": true, it will use the following command to jump to the directory cd xxx / xxx However, the cmd.exe command "cd", without the parameter "/ d", will not be able to enter the corresponding directory. It seems to be used in conjunction with " code-runner.cwd ". I don't know if this is a bug or the original intention? At present, I configure the configuration of the corresponding language in "code-runner.executorMap", and add cd / d $ dirat the beginning.

rl-utility-man commented 4 years ago

I think this is a bug with an easy fix.

If the shell is the default, powershell, setting fileDirectoryAsCwd to true will issue the command: cd "x:\path\to\directory" and it will succeed.

If the shell is CMD.exe, setting fileDirectoryAsCwd to true will issue the command: cd "x:\path\to\directory" before it tries to execute the code and the cd command will fail to change the directory if the current code runner directory is not on the drive X.

This is easy to reproduce: set the shell to cmd.exe and set fileDirectoryAsCwd to true in settings.json create a file called cd.bat on a flash drive with the contents "cd" The cd command alone will echo the current directory to the console. Open the folder "C:\users" in VS Code. Open cd.bat without changing the VS Code directory. Use code runner to execute cd.bat. Code runner will issue a command like cd "F:\" and then execute cd.bat, which will show that the directory is still C:\users

If the shell is cmd.exe and fileDirectoryAsCwd is true, the fix is to either: issue the command $driveLetter: before issuing the command cd "$dir" or issue the command cd "$dir" /d

A workaround like those in the original post works too, but is necessary because fileDirectoryAsCwd is not reliable.

Thanks for a very useful tool.

NamesMT commented 3 years ago

Bump :(