On 2020-09-30 23:48, Ian Lance Taylor 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.

There is an issue (closed I believe) that ended up asking whether it could be
allowed before running any go routines. The response was, along the lines of
worth it?, why not just run "/bin/sh program &"

-- 
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/64d3f6a5-6b12-f9e1-f663-1eb1f7254145%40gmail.com.

Reply via email to