替换当前进程

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

Replace current process

问题

在Go语言中,可以使用os/exec包来替换当前正在执行的进程。

是否可以在Go语言中做到同样的事情?

英文:

In Ruby, you can use Kernel.exec to replace the current executing process by the one triggered.

Is it possible to do the same thing in Go?

答案1

得分: 20

这相当于Kernel.exec:

package main

import "fmt"
import "syscall"

func main() {
    if err := syscall.Exec("/bin/ls", []string{"ls", "-l"}, []string{}); err != nil {
      fmt.Println(err)
    }
}

但它不具备可移植性。

英文:

This is the equivalent to Kernel.exec:

package main

import "fmt"
import "syscall"

func main() {
    if err := syscall.Exec("/bin/ls", []string{"ls", "-l"}, []string{}); err != nil {
      fmt.Println(err)
    }
}

but it is not portable.

huangapple
  • 本文由 发表于 2013年6月28日 09:03:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/17355667.html
匿名

发表评论

匿名网友

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

确定