1. 首页
  2. 主题
  3. Go问与答

Go程序注册Windows服务有问

Jie795 · · 1439 次点击
刚学Go想写一个 一秒读取一次剪切板然后写入redis的服务, 但是使用for死循环启动服务一直报错, 无法启动, 请问如何解决这个问题 ![image.png](https://static.golangjob.cn/240920/30968e8502ae221361114aece773828c.png) ![image.png](https://static.golangjob.cn/240920/7f415a803994f02c140a75c67b5f8ba0.png)
要想让 windows 正确的识别该程序是个 服务,需要实现 [service.Handler](https://github.com/golang/sys/blob/48aad76ed3ac439edae50adb78dbdbc46080878a/windows/svc/service.go#L109-L123) 接口,可以查看官方提供的 [Example 程序](https://github.com/golang/sys/blob/48aad76ed3ac439edae50adb78dbdbc46080878a/windows/svc/example/service.go#L23)。 ![swappy-20240920_164617.png](https://static.golangjob.cn/240920/d19194a5c92ab331dffc1dbe0ff66a51.png)
#1
更多评论
好像是不能输出,不能写fmt.Println
#2
windows服务是特殊的写法,在main函数中特殊处理启动。和命令行启动写法是不一样的。
#3

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中