subprocess

package
v1.77.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package subprocess allows you to spawn new processes, log their output/error and obtain their return codes.

  • Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanKillOfCommand added in v1.62.0

func CleanKillOfCommand(ctx context.Context, cmd *exec.Cmd) (err error)

func ConvertCommandError added in v1.62.0

func ConvertCommandError(err error) error

func Execute

func Execute(ctx context.Context, loggers logs.Loggers, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) error

Execute executes a command (i.e. spawns a subprocess).

func ExecuteAs added in v1.48.0

func ExecuteAs(ctx context.Context, loggers logs.Loggers, messageOnStart string, messageOnSuccess, messageOnFailure string, as *commandUtils.CommandAsDifferentUser, cmd string, args ...string) error

ExecuteAs executes a command (i.e. spawns a subprocess) as a different user.

func ExecuteAsWithEnvironment added in v1.60.0

func ExecuteAsWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnvVars []string, messageOnStart string, messageOnSuccess, messageOnFailure string, as *commandUtils.CommandAsDifferentUser, cmd string, args ...string) (err error)

ExecuteAsWithEnvironment executes a command (i.e. spawns a subprocess) as a different user. It allows to specify the environment the subprocess should use. Each entry is of the form "key=value".

func ExecuteWithEnvironment added in v1.60.0

func ExecuteWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnvVars []string, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) (err error)

ExecuteWithEnvironment executes a command (i.e. spawns a subprocess). It allows to specify the environment the subprocess should use. Each entry is of the form "key=value".

func ExecuteWithSudo added in v1.48.0

func ExecuteWithSudo(ctx context.Context, loggers logs.Loggers, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) error

ExecuteWithSudo executes a command (i.e. spawns a subprocess) as root.

func Output added in v1.47.0

func Output(ctx context.Context, loggers logs.Loggers, cmd string, args ...string) (string, error)

Output executes a command and returns its output (stdOutput and stdErr are merged) as string.

func OutputAs added in v1.48.0

func OutputAs(ctx context.Context, loggers logs.Loggers, as *commandUtils.CommandAsDifferentUser, cmd string, args ...string) (string, error)

OutputAs executes a command as a different user and returns its output (stdOutput and stdErr are merged) as string.

func OutputAsWithEnvironment added in v1.60.0

func OutputAsWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnvVars []string, as *commandUtils.CommandAsDifferentUser, cmd string, args ...string) (output string, err error)

OutputAsWithEnvironment executes a command as a different user and returns its output (stdOutput and stdErr are merged) as string. It allows to specify the environment the subprocess should use. Each entry is of the form "key=value".

func OutputWithEnvironment added in v1.60.0

func OutputWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnvVars []string, cmd string, args ...string) (string, error)

OutputWithEnvironment executes a command and returns its output (stdOutput and stdErr are merged) as string. It allows to specify the environment the subprocess should use. Each entry is of the form "key=value".

Types

type Subprocess

type Subprocess struct {
	// contains filtered or unexported fields
}

Subprocess describes what a subprocess is as well as any monitoring it may need.

func New

func New(ctx context.Context, loggers logs.Loggers, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) (*Subprocess, error)

New creates a subprocess description.

func NewWithEnvironment added in v1.60.0

func NewWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnvVars []string, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) (p *Subprocess, err error)

NewWithEnvironment creates a subprocess description. It allows to specify the environment the subprocess should use. Each entry is of the form "key=value".

func (*Subprocess) Cancel

func (s *Subprocess) Cancel()

Cancel interrupts an ongoing process. This method is idempotent.

func (*Subprocess) Check

func (s *Subprocess) Check() error

Check checks whether the subprocess is correctly defined.

func (*Subprocess) Execute

func (s *Subprocess) Execute() (err error)

Execute executes the command and waits for completion.

func (*Subprocess) IsOn

func (s *Subprocess) IsOn() bool

IsOn states whether the subprocess is running or not.

func (*Subprocess) Restart

func (s *Subprocess) Restart() (err error)

Restart restarts a process. It will stop the process if currently running.

func (*Subprocess) Setup

func (s *Subprocess) Setup(ctx context.Context, loggers logs.Loggers, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) (err error)

Setup sets up a sub-process i.e. defines the command cmd and the messages on start, success and failure.

func (*Subprocess) SetupAs added in v1.48.0

func (s *Subprocess) SetupAs(ctx context.Context, loggers logs.Loggers, messageOnStart string, messageOnSuccess, messageOnFailure string, as *commandUtils.CommandAsDifferentUser, cmd string, args ...string) (err error)

SetupAs is similar to Setup but allows the command to be run as a different user.

func (*Subprocess) SetupAsWithEnvironment added in v1.60.0

func (s *Subprocess) SetupAsWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnv []string, messageOnStart string, messageOnSuccess, messageOnFailure string, as *commandUtils.CommandAsDifferentUser, cmd string, args ...string) (err error)

SetupAsWithEnvironment is similar to Setup but allows the command to be run as a different user. Compared to SetupAs, it allows specifying additional environment variables to be used by the process.

func (*Subprocess) SetupWithEnvironment added in v1.60.0

func (s *Subprocess) SetupWithEnvironment(ctx context.Context, loggers logs.Loggers, additionalEnv []string, messageOnStart string, messageOnSuccess, messageOnFailure string, cmd string, args ...string) (err error)

SetupWithEnvironment sets up a sub-process i.e. defines the command cmd and the messages on start, success and failure. Compared to Setup, it allows specifying additional environment variables to be used by the process.

func (*Subprocess) Start

func (s *Subprocess) Start() (err error)

Start starts the process if not already started. This method is idempotent.

func (*Subprocess) Stop

func (s *Subprocess) Stop() (err error)

Stop stops the process straight away if currently working without waiting for completion. This method should be used in combination with `Start`. However, in order to interrupt a process however it was started (using `Start` or `Execute`), prefer `Cancel`. This method is idempotent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL