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

Fix (code) editor launch on Windows #33

Merged
merged 1 commit into from
Dec 21, 2020
Merged

Conversation

atifaziz
Copy link
Contributor

@atifaziz atifaziz commented Dec 20, 2020

On Windows, running:

dotnet config -e

fails with the following error:

The specified executable is not a valid application for this OS platform.

when I do have Visual Studio Code installed.

I am using dotnet-config 1.0 RC1.

The problem is how the tool seems to be using where on Windows to locate code and using its output. Running where code in a shell on my box gives two paths:

> where.exe code
C:\Users\johndoe\AppData\Local\Programs\Microsoft VS Code\bin\code
C:\Users\johndoe\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd

The tool uses the first line of the output only, which identifies a sh script, not a Windows binary.

This PR fixes the issue by using PATHEXT environment variable on Windows to get the list of known executable extensions and sending code plus those extensions to where. For example, on my machine, PATHEXT has the value:

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL

So now, where is run by the tool as follows:

where code.COM code.EXE code.BAT code.CMD code.VBS code.VBE code.JS code.JSE code.WSF code.WSH code.MSC code.CPL

The output I get is:

C:\Users\johndoe\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
INFO: Could not find "code.COM".
INFO: Could not find "code.EXE".
INFO: Could not find "code.BAT".
INFO: Could not find "code.VBS".
INFO: Could not find "code.VBE".
INFO: Could not find "code.JS".
INFO: Could not find "code.JSE".
INFO: Could not find "code.WSF".
INFO: Could not find "code.WSH".
INFO: Could not find "code.MSC".
INFO: Could not find "code.CPL".

Fortunately, the not found cases go to standard error so the existing code that just picks up the first line of standard output doesn't need any change. I did however have to redirect standard error to avoid having the not found cases appear where dotnet config -e is run.

Fixes #35

@kzu
Copy link
Collaborator

kzu commented Dec 21, 2020

Awesome bug and fix! Thanks!

@kzu kzu merged commit 5a5e802 into dotnetconfig:main Dec 21, 2020
@atifaziz atifaziz deleted the fix-win-edit branch December 21, 2020 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix (code) editor launch on Windows
2 participants