英文:
Reading a process name how it is displayed in Windows Task Manager in Golang
问题
我目前正在尝试读取在Windows任务管理器中表示的进程名称的Go代码。
然而,当我在Go中读取时,它总是显示为可执行文件。我正在尝试获取它在任务管理器中的名称。
代码:
package main
import (
"fmt"
"github.com/shirou/gopsutil/process"
)
func main() {
p, _ := process.Processes()
for _, pr := range p {
fmt.Println(pr.Name())
}
}
这将输出所有进程的名称,但没有一个与这里显示的名称匹配:
我正在尝试读取显示有歌曲标题的Spotify进程名称。
英文:
I'm currently trying to read the name of a process in Go how it is represented in the windows task manager.
However, when I read it in Go it is displayed always as the executable. I'm trying to get it how it is named in the task manager.
Code:
package main
import (
"fmt"
"github.com/shirou/gopsutil/process"
)
func main() {
p, _ := process.Processes()
for _, pr := range p {
fmt.Println(pr.Name())
}
}
This outputs all process names but none match how it is shown here:
I am trying to read the Spotify process name that is displayed with the song title.
答案1
得分: 0
获取窗口标题
每次打开“Windows任务管理器”时,它都会搜索.Net process.MainWindowTitle属性,所以你不能使用gopsutil来获取窗口标题...你需要使用一些针对.NET Core Runtime的Go封装,也许这个会有帮助...甚至可以使用C#而不是Golang。
获取当前在Spotify上播放的曲目
Spotify有针对这种情况的API使用文档,所以你只需要生成授权令牌并将下一个curl请求转换为golang的fetch函数。
curl -X "GET" "https://api.spotify.com/v1/me/player/currently-playing?market=UA" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <<YOUR TOKEN>>"
英文:
Get window title
Each time you open the "Windows Task Manager" it searches for .Net process.MainWindowTitle property, so you cant grep Windows title using gopsutil ... you have to use some Go wrapper for the .NET Core Runtime , not sure maybe this one would be helpful ... or even use C# instead of Golang
Get currently playing track on Spotify
Spotify has awesome docs with API usage for such case
so you only need to generate auth token and convert next curl request to golang fetch function
curl -X "GET" "https://api.spotify.com/v1/me/player/currently-playing?market=UA" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <<YOUR TOKEN>>"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论