fdexec

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 fdexec runs a command by file descriptor.

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

	// 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(fd *embedexe.FD, arg ...string) *Cmd

Command returns the Cmd struct to execute the program referenced by the file descriptor with the given arguments.

Example
package main

import (
	"log"
	"os"

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

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

	fd, err := embedexe.Open(exe, "echo")
	if err != nil {
		log.Fatalln(err)
	}

	cmd := fdexec.Command(fd, "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, fd *embedexe.FD, 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.

Jump to

Keyboard shortcuts

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