Help us shape the future of Go! Take the 2026 Go Developer Survey

stdioconn

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: ISC Imports: 6 Imported by: 0

Documentation

Overview

Package stdioconn provides a net.Conn over a pair of files, such as the standard input and output of a process or the pipes to a child.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is a net.Conn that wraps a pipe and optionally an exec.Cmd.

func New

func New(stdin, stdout *os.File, opts ...Option) *Conn

New returns a Conn reading from stdin and writing to stdout.

func Spawn

func Spawn(cmd *exec.Cmd) (*Conn, error)

Spawn starts cmd with its standard input and output connected to the returned Conn. Close waits for cmd to exit. Stdin and Stdout should not be already set.

func (*Conn) Close

func (c *Conn) Close() error

Close closes both files and waits for the command, if any. It is safe to call more than once; later calls return the first result.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns a placeholder address.

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Read reads from stdin.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns a placeholder address.

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline on stdin.

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline on stdout.

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write writes to stdout.

type Option

type Option func(*Conn)

Option configures a Conn.

func WithCmd

func WithCmd(cmd *exec.Cmd) Option

WithCmd makes Close wait for cmd to exit and return its error.

func WithOnClose

func WithOnClose(fn func()) Option

WithOnClose makes Close call fn, once, before closing the files.

Jump to

Keyboard shortcuts

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