github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/rpcplugin/process_unix.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 // +build !windows 5 6 package rpcplugin 7 8 import ( 9 "context" 10 "io" 11 "os" 12 "os/exec" 13 ) 14 15 type process struct { 16 command *exec.Cmd 17 } 18 19 func newProcess(ctx context.Context, path string) (Process, io.ReadWriteCloser, error) { 20 ipc, childFiles, err := NewIPC() 21 if err != nil { 22 return nil, nil, err 23 } 24 defer childFiles[0].Close() 25 defer childFiles[1].Close() 26 27 cmd := exec.CommandContext(ctx, path) 28 cmd.Stdout = os.Stdout 29 cmd.Stderr = os.Stderr 30 cmd.ExtraFiles = childFiles 31 err = cmd.Start() 32 if err != nil { 33 ipc.Close() 34 return nil, nil, err 35 } 36 37 return &process{ 38 command: cmd, 39 }, ipc, nil 40 } 41 42 func (p *process) Wait() error { 43 return p.command.Wait() 44 } 45 46 func inheritedProcessIPC() (io.ReadWriteCloser, error) { 47 return InheritedIPC(3, 4) 48 }