将os.Signal转换为字符串以便能够在文件中打印它。

huangapple go评论77阅读模式
英文:

Convert os.Signal to string to be able to print it in afile

问题

我需要将 os.signal 类型转换为字符串,以便能够将其保存到文件中。

err := ioutil.WriteFile("out", []byte(sig), 0644)

我得到了以下错误:

./signals.go:37: 无法将 sig (类型为 os.Signal) 作为 ioutil.WriteFile 的参数类型 []byte 使用。

英文:

I need to Convert the os.signal type to string to be able to save it in a file.

err := ioutil.WriteFile("out", sig, 0644)

I get error like this:

./signals.go:37: cannot use sig (type os.Signal) as type []byte in argument to ioutil.WriteFile

答案1

得分: 5

你可以执行以下操作:

err := ioutil.WriteFile("out", []byte(sig.String()), 0644)
英文:

You can do

err := ioutil.WriteFile("out", []byte(sig.String()), 0644)

huangapple
  • 本文由 发表于 2016年1月24日 21:47:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/34976564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定