cmd

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cmd

Package cmd

Package cmd

Package cmd 系统调用exec包

实现了命令的快速调用 使用New()创建一个Cmder对象 c := NewCmder() c.Exec("ls")

实现了基于windows/linux的daemon模式启动 cmd.Daemon() 或 cmd.DaemonCall(cmd)调用任意命令

Index

Constants

View Source
const (
	Bash = "bash"
	Zsh  = "zsh"
	Fish = "fish"
	Sh   = "sh"
)
View Source
const (
	BASH      = ".sh"
	ShellPerm = 0700
	EmptyBash = "#!/usr/bin/env bash"
)
View Source
const (
	DefaultMask = 0117 // 默认0660
)

Variables

View Source
var Cmd = Cmder{/* contains filtered or unexported fields */}

Functions

func Daemon added in v1.1.5

func Daemon(exclude string)

Daemon 以daemon模式运行当前的程序 限制需要指定daemon arg来用于排除

func DaemonCall added in v1.1.5

func DaemonCall(program string, args ...string) error

DaemonCall daemon调用任意指定的命令

func DaemonWith added in v1.1.5

func DaemonWith(exclude string) (int, error)

DaemonWith 返回pid和错误

func Fork added in v1.1.5

func Fork(arg0 string, argv []string, attr *syscall.ProcAttr) (int, error)

Fork on UNIX

func InitCmder added in v1.1.5

func InitCmder(shell string)

func NewBash

func NewBash(dst, sh string) error

NewBash 新建一个带命令的shell文件

func NewEmptyBash

func NewEmptyBash(dst string) error

NewEmptyBash 新建一个空shell文件 dst为文件生成的目录 dst为.sh结尾的文件

Types

type Cmder added in v1.1.5

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

func New added in v1.1.5

func New(shell string, mask int) Cmder

func NewCmder added in v1.1.5

func NewCmder() Cmder

NewCmder default BASH

func (Cmder) Exec added in v1.1.5

func (c Cmder) Exec(sh string) error

func (Cmder) ExecAsync added in v1.1.5

func (c Cmder) ExecAsync(sh string, ctx context.Context) error

func (Cmder) ExecCtx added in v1.1.5

func (c Cmder) ExecCtx(sh string, ctx context.Context) ([]byte, error)

func (Cmder) ExecOpt added in v1.1.5

func (c Cmder) ExecOpt(sh string) ([]byte, error)

func (Cmder) ExecStr added in v1.1.5

func (c Cmder) ExecStr(sh string) (string, error)

func (Cmder) Run added in v1.1.5

func (c Cmder) Run(sh string) *exec.Cmd

Run 返回原生的cmd

func (Cmder) RunContext added in v1.1.5

func (c Cmder) RunContext(sh string, ctx context.Context) *exec.Cmd

Jump to

Keyboard shortcuts

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