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

windows 10 version not recognized #5

Closed
xiorcal opened this issue Jan 12, 2018 · 2 comments
Closed

windows 10 version not recognized #5

xiorcal opened this issue Jan 12, 2018 · 2 comments

Comments

@xiorcal
Copy link
Contributor

xiorcal commented Jan 12, 2018

hi!

trying to use a basic err := beeep.Notify("Title", "Message body", "assets/icon128.png")
I go t the following panic : panic: exec: "msg": executable file not found in %PATH%

I dug a little and found that getWindowsVersionString() returns unknown on my computer

package main

import (
	"bytes"
	"fmt"
	"os/exec"
	"strings"
)

func main() {
	cmd := exec.Command("cmd", "ver")
	var out bytes.Buffer
	cmd.Stdout = &out
	err := cmd.Run()
	if err != nil {
		panic(err)
	}
	fmt.Println(out.String())
	s := strings.Replace(out.String(), "\r\n", "", -1)
	p1 := strings.Index(s, "[Version")
	p2 := strings.Index(s, "]")
	var ver string
	if p1 == -1 || p2 == -1 {
		ver = "unknown"
	} else {
		ver = s[p1+9 : p2]
	}
	fmt.Printf("%v\n", ver)
}

outputs

go run .\main.go
Microsoft Windows [version 10.0.16299.192]
(c) 2017 Microsoft Corporation. Tous droits r�serv�s.


unknown

seems to me that it comes from the lower case "version" instead of the expected "Version"

@xiorcal
Copy link
Contributor Author

xiorcal commented Jan 12, 2018

i'm making a PR

gen2brain added a commit that referenced this issue Jan 12, 2018
fixing issue #5 about windows 10 version not being recognized
@xiorcal xiorcal closed this as completed Jan 13, 2018
@Equim-chan
Copy link
Contributor

We can't assume the client is always running Windows in English.

On my platform, cmd ver prints

Microsoft Windows [版本 10.0.16299.192]
(c) 2017 Microsoft Corporation。保留所有权利。
...
>cmd ver < NUL | xxd
00000000: 4d69 6372 6f73 6f66 7420 5769 6e64 6f77  Microsoft Window
00000010: 7320 5bb0 e6b1 be20 3130 2e30 2e31 3632  s [.... 10.0.162
00000020: 3939 2e31 3932 5d0d 0a28 6329 2032 3031  99.192]..(c) 201
00000030: 3720 4d69 6372 6f73 6f66 7420 436f 7270  7 Microsoft Corp
00000040: 6f72 6174 696f 6ea1 a3b1 a3c1 f4cb f9d3  oration.........
...

The best fix should be querying registry directly instead of using this trick. I'll try to make a PR soon.

Equim-chan added a commit to Equim-chan/beeep that referenced this issue Feb 9, 2018
gen2brain added a commit that referenced this issue Feb 9, 2018
windows: query version from registry, fix #5
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

No branches or pull requests

2 participants