batch

package
v0.0.0-...-f4e3d25 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package batch implements the DOS batch file execution engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallSignal

type CallSignal struct {
	Path  string
	Label string
	Args  []string
}

CallSignal is returned by CALL. When Label is non-empty it is a local subroutine call (CALL :label); otherwise Path names the batch file to invoke.

func (CallSignal) Error

func (c CallSignal) Error() string

type ExitBatchSignal

type ExitBatchSignal struct{ Code int }

ExitBatchSignal is returned by EXIT /B to end the current batch subroutine (or the current batch file) without exiting the shell.

func (ExitBatchSignal) Error

func (e ExitBatchSignal) Error() string

type ExitError

type ExitError struct{ Code int }

ExitError is returned by the EXIT builtin to signal the shell to exit.

func (ExitError) Error

func (e ExitError) Error() string

type GotoSignal

type GotoSignal struct{ Label string }

GotoSignal is returned by GOTO to signal the batch engine to jump to a label.

func (GotoSignal) Error

func (g GotoSignal) Error() string

type State

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

State is the execution state for a running batch file.

func Load

func Load(path string, args []string) (*State, error)

Load reads a batch file and returns a ready State. args[0] should be the script path (%0); args[1:] are %1..%9.

func New

func New(lines []string, args []string) *State

New returns a State for the given lines and argument vector.

func (*State) Goto

func (s *State) Goto(label string) error

Goto sets the program counter to the line after the named label. The special label EOF (or :EOF) jumps past the end of the file. Returns an error if the label is not found.

func (*State) Run

func (s *State) Run(
	runLine func(string) error,
	runBatch func(dosPath string, args []string) error,
	stderr io.Writer,
) error

Run executes the batch file line by line.

  • runLine executes a single expanded line (typically Shell.RunLine).
  • runBatch executes a nested batch file given a DOS path and args (for CALL).
  • stderr receives diagnostic messages.

Run returns a non-nil error only for ExitError (shell exit) or unexpected errors propagated from runLine.

Jump to

Keyboard shortcuts

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