exec

package
v0.0.0-...-3fba3b1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

Package exec runs a command stored as bytes in memory.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	*exec.Cmd

	// Exe holds the executable as a byte array.
	Exe []byte

	// The command name (proctitle) stored in /proc/self/cmdline.
	// Defaults to the command name of the current running process.
	Name string

	// Enable debug messages to stderr.
	Verbose bool
	// contains filtered or unexported fields
}

Cmd is a wrapper around the os/exec Cmd struct.

func Command

func Command(exe []byte, arg ...string) *Cmd

Command returns the Cmd struct to execute the program held in exe with the given arguments.

Example
package main

import (
	"log"
	"os"

	"codeberg.org/msantos/embedexe/exec"
)

func main() {
	exe, err := os.ReadFile("/bin/echo")
	if err != nil {
		log.Fatalln(err)
	}

	cmd := exec.Command(exe, "test")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	if err := cmd.Run(); err != nil {
		log.Fatalln(err)
	}

}
Output:

test

func CommandContext

func CommandContext(ctx context.Context, exe []byte, arg ...string) *Cmd

CommandContext returns a Cmd struct using the provided context.

func (*Cmd) CombinedOutput

func (cmd *Cmd) CombinedOutput() ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and standard error.

func (*Cmd) Output

func (cmd *Cmd) Output() ([]byte, error)

Output runs the command and returns its standard output.

func (*Cmd) Run

func (cmd *Cmd) Run() error

Run starts the specified command and waits for it to complete.

func (*Cmd) Start

func (cmd *Cmd) Start() error

Start starts the specified command but does not wait for it to complete.

func (*Cmd) Wait

func (cmd *Cmd) Wait() error

Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete.

The command must have been started by Start.

Jump to

Keyboard shortcuts

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