On Wed, Sep 30, 2020 at 3:33 PM Chris Tierney <christier...@gmail.com> wrote:
>
> Is there a way to accomplish this in go? Normally what I'd do is `fork` a 
> process that would handle writing to a pipe, `dup` the read end of the pipe 
> to stdin and then `exec` to the process I want to run, but `syscall` doesn't 
> have a `Fork`. I could probably use `import "C"` but at that point I would 
> just rather write the tool in C.

There is no syscall.Fork because Go programs are always
multi-threaded, and there is no safe way to fork a multi-threaded
program.  fork/exec can be made safe if written with care, but plain
fork cannot.

The closest you can come is what you showed later, where you fork/exec
a program to feed standard input back to your own program.  Or you
could, if possible, put the new process's standard input in a file,
and syscall.Open/syscall.Dup before you syscall.Exec.

Ian

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU1cMbbFLHAvPyexDm1jU3n_zjbaS3_4vP8yJ%2BN%2BVKX%3DQ%40mail.gmail.com.

Reply via email to