在Go语言中创建/退出进程的回调函数。

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

Process creation/exit callback in Go lang

问题

在MAC OS上,我想在Golang中创建/退出进程(尤其是退出)时使用回调函数。一旦进程退出,我需要执行一些操作。非常感谢任何指导或帮助。

英文:

On MAC OS I want process create/exit (more so exit) callbacks in Golang. Once the process exits I have to do some activity.
Any pointers or help is appreciated.

答案1

得分: 1

run命令文档中:

> Run启动指定的命令并等待其完成。

您可以使用以下代码运行命令:

cmd := exec.Command("firefox")

err := cmd.Run()

if err != nil {
    log.Fatal(err)
}

// 在进程退出后执行其他操作
英文:

From run command documentation:

> Run starts the specified command and waits for it to complete.

You can run a command with:

cmd := exec.Command("firefox")

err := cmd.Run()

if err != nil {
    log.Fatal(err)
}

// DO SOMETHING AFTER PROCESS EXIT

huangapple
  • 本文由 发表于 2022年9月26日 17:57:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/73852461.html
匿名

发表评论

匿名网友

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

确定