Any access to exec system call?

811 views
Skip to first unread message

Mike Bosland

unread,
Mar 20, 2013, 1:57:40 PM3/20/13
to golan...@googlegroups.com
I have a simple shell script that either execs a production version or a canary version of another binary.
I don't want any shell interpretation of command arguments, I just want to pass them along.  My shell fu is not so good and I'm interested in doing this in Go.

I really just want exec (replacing the Go process).  Is that available or should I use python?

Kevin Gillette

unread,
Mar 20, 2013, 3:24:27 PM3/20/13
to golan...@googlegroups.com, bosl...@google.com
On unix-like systems: http://golang.org/pkg/syscall/#Exec

Carlos Castillo

unread,
Mar 20, 2013, 7:27:16 PM3/20/13
to golan...@googlegroups.com, bosl...@google.com
Also if you are solely interested in starting a new process, and not having the current one continue, using one of the portable methods followed by os.Exit() also works.

BTW: any method in go of starting a new process will not do shell substitutions anyway.

I do agree with Kevin though... If you are looking for an equivalent to the exec* family of syscalls, then syscall.Exec will suffice, it just isn't portable to windows (will return an error). All other go supported systems are UNIX based, or unix-like enough to follow the fork/exec paradigm.

Mike Bosland

unread,
Mar 21, 2013, 5:16:41 AM3/21/13
to Carlos Castillo, golan...@googlegroups.com
Excellent.  I'll stick with sys.Exec as it's a Un*x only application anyway.  My explicit goal is no shell substitutions.  :)

Russ Cox

unread,
Mar 21, 2013, 9:15:43 PM3/21/13
to Mike Bosland, Carlos Castillo, golang-nuts
Note that for the purposes of this discussion OS X is not a Unix (exec doesn't work from threaded programs, and all Go programs are threaded).

Russ

Dave Cheney

unread,
May 10, 2013, 5:58:03 PM5/10/13
to ma...@jamiehillman.co.uk, golang-nuts
There are a few problems with this approach.

* Your main() func runs in a goroutine
* An unknown number of goroutines can be started during the init
phase, including packages you import
* Go has several `system` goroutines that are started before main as well.

On Sat, May 11, 2013 at 4:39 AM, <ma...@jamiehillman.co.uk> wrote:
> Hi,
>
> Sorry to bump an old thread, but I'm trying to write a program that execs
> tmux - doing something along the lines of tmuxinator (but much simpler).
> I've noticed this OS X limitation that Russ mentions here. Is there any way
> to make exec work - I thought there wouldn't be any threads until I launch a
> goroutine? I could just output my commands from go and eval them in bash
> but I wanted to have a self contained executable and not be tied to a
> particular shell. Any idea how I can get around this?
>
> Thanks,
>
> Jamie
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages