API
#os/exec
Xu 0.8.8 API
import: #os/exec
counts: 3 fns, 9 methods, 1 types, 0 consts, 0 ifaces
Process execution with argument arrays, run/output/combined_output, start/wait, and stdin/stdout pipes.
struct Cmd
pub struct Cmd {
pub path string
pub args []string
pub dir string
pub ctx context.Context
pub has_ctx int
}
Purpose
`os/exec` subset: command / run / output / combined_output command_context / start / wait / stdout_pipe / stdin_pipe. Run is direct exec, not a shell. PATH lookup is look_path. stdout_pipe / stdin_pipe are Unix-only (Windows throws). stdin must be written and the write end closed before start.
Parameters
path string- filesystem path
args []string- variadic arguments
dir string- directory
ctx context.Context- field (context.Context)
has_ctx int- field (int)
(&mut Cmd) set_dir
pub fn (c &mut Cmd) set_dir(dir string)
Purpose
Method on `&mut Cmd`: set dir.
Parameters
c &mut Cmd- receiver &mut Cmd (exclusive borrow)
dir string- directory (string)
command
pub fn command(name string, args <-> string) Cmd
Purpose
command; returns Cmd.
Parameters
name string- name (string)
args <-> string- variadic string (seen inside the function as []string)
Returns
Cmd — a value of this type
command_context
pub fn command_context(ctx context.Context, name string, args <-> string) Cmd
Purpose
Command context.
Parameters
ctx context.Context- ctx (context.Context)
name string- name (string)
args <-> string- variadic string (seen inside the function as []string)
Returns
Cmd — a value of this type
look_path
pub fn look_path(file string) string
Purpose
Look path. Throws on failure.
Parameters
file string- file (string)
Returns
string — result string
(&Cmd) run
pub fn (c &Cmd) run() int
Purpose
Call `run` on `&Cmd`. Throws on failure.
Parameters
c &Cmd- receiver &Cmd (borrow)
Returns
int — a value of this type
(&Cmd) output
pub fn (c &Cmd) output() string
Purpose
Call `output` on `&Cmd`. Throws on failure.
Parameters
c &Cmd- receiver &Cmd (borrow)
Returns
string — result string
(&mut Cmd) close_unstarted_pipes
pub fn (c &mut Cmd) close_unstarted_pipes()
Purpose
Release pipe endpoints when setup fails before start. Once started, the runtime owns the child endpoints; closing those stale fd numbers is unsafe.
Parameters
c &mut Cmd- receiver &mut Cmd (exclusive borrow)
(&mut Cmd) stdout_pipe
pub fn (c &mut Cmd) stdout_pipe() os.File
Purpose
Method on `&mut Cmd`: stdout pipe. Throws on failure.
Parameters
c &mut Cmd- receiver &mut Cmd (exclusive borrow)
Returns
os.File — a value of this type
(&mut Cmd) stdin_pipe
pub fn (c &mut Cmd) stdin_pipe() os.File
Purpose
Method on `&mut Cmd`: stdin pipe. Throws on failure.
Parameters
c &mut Cmd- receiver &mut Cmd (exclusive borrow)
Returns
os.File — a value of this type
(&mut Cmd) start
pub fn (c &mut Cmd) start() int
Purpose
Call `start` on `&mut Cmd`. Throws on failure.
Parameters
c &mut Cmd- receiver &mut Cmd (exclusive borrow)
Returns
int — a value of this type
(&mut Cmd) wait
pub fn (c &mut Cmd) wait() int
Purpose
Call `wait` on `&mut Cmd`. Throws on failure.
Parameters
c &mut Cmd- receiver &mut Cmd (exclusive borrow)
Returns
int — a value of this type
(&Cmd) combined_output
pub fn (c &Cmd) combined_output() string
Purpose
Method on `&Cmd`: combined output. Throws on failure.
Parameters
c &Cmd- receiver &Cmd (borrow)
Returns
string — result string