Files
exec/process/process.go
T
2026-06-18 22:39:18 -03:00

45 lines
1.1 KiB
Go

package process
import (
"context"
"fmt"
"io"
"os"
)
type Env map[string]string
func (env Env) ToSlice() []string {
data := []string{}
for key, value := range env {
data = append(data, fmt.Sprintf("%s=%s", key, value))
}
return data
}
// Generic struct to start Process
type Exec struct {
Arguments []string // command and arguments
Cwd string // Workdir path
Environment Env // Envs to add to process
Context context.Context // Context to cancel process run
Stdout, Stderr io.Writer // Stdout and Stderr log to attach process
Stdin io.Reader // Stdin reader
}
// Universal process struct
type Proc interface {
Start(options *Exec) error // Start process in background
Kill() error // Kill process with SIGKILL
Close() error // Send ctrl + c (SIGINT) and wait process end
Wait() error // Wait process
Signal(s os.Signal) error // Send signal to process
ExitCode() (int, error) // return process exit code, if running wait to get exit code
AttachStdin(io.Reader) error
AttachStdout(io.Writer) error
AttachStderr(io.Writer) error
}