Replacing the current go process with os.execvpe

342 views
Skip to first unread message

Mirko Friedenhagen

unread,
Oct 16, 2018, 10:13:59 AM10/16/18
to golang-nuts
Hello everybody,

I am on my way to replace a Python script which writes several configuration files before replacing itself with another program (e.g. bash). For that I use https://docs.python.org/3/library/os.html#os.execv.

Is there any equivalent in Golang? I do not use any fancy go routines in the script, the only output are some log lines. Is it OK to just call something like `syscall.Exec("/bin/bash", args, os.Environ())`

Regards
Mirko

Jan Mercl

unread,
Oct 16, 2018, 11:02:37 AM10/16/18
to Mirko Friedenhagen, golang-nuts
On Tue, Oct 16, 2018 at 4:14 PM Mirko Friedenhagen <mfried...@gmx.de> wrote:

> Is it OK to just call something like `syscall.Exec("/bin/bash", args, os.Environ())`

I'd recommend to first try exec.Command.
--

-j

Ian Lance Taylor

unread,
Oct 16, 2018, 11:02:46 AM10/16/18
to Mirko Friedenhagen, golang-nuts
Yes, syscall.Exec seems like the closest equivalent. It only works on
Unix systems.

Ian

Mirko Friedenhagen

unread,
Oct 16, 2018, 3:15:12 PM10/16/18
to golang-nuts
Thanks, syscall.Exec seems to be what I want then.
Reply all
Reply to author
Forward
0 new messages