gocommand

package module
v0.0.0-...-41f1667 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 5 Imported by: 0

README

gocommand

package main

import (
	"github.com/lizongshen/gocommand"
	"log"
)

func main() {
	_, out, err := gocommand.NewCommand().Exec("ls /")
	if err != nil {
		log.Panic(err)
	}

	log.Println(out)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commander

type Commander interface {
	// 执行命令行并返回结果
	// args: 命令行参数
	// return: 进程的pid, 命令行结果, 错误消息
	Exec(args ...string) (int, string, error)

	// 异步执行命令行并通过channel返回结果
	// stdout: chan结果
	// args: 命令行参数
	// return: 进程的pid
	// exception: 协程内的命令行发生错误时,会panic异常
	ExecAsync(stdout chan string, args ...string) int

	// 执行命令行(忽略返回值)
	// args: 命令行参数
	// return: 错误消息
	ExecIgnoreResult(args ...string) error
}

命令行接口

func NewCommand

func NewCommand() Commander

Command的初始化函数

type LinuxCommand

type LinuxCommand struct {
}

LinuxCommand结构体

func NewLinuxCommand

func NewLinuxCommand() *LinuxCommand

LinuxCommand的初始化函数

func (*LinuxCommand) Exec

func (lc *LinuxCommand) Exec(args ...string) (int, string, error)

执行命令行并返回结果 args: 命令行参数 return: 进程的pid, 命令行结果, 错误消息

func (*LinuxCommand) ExecAsync

func (lc *LinuxCommand) ExecAsync(stdout chan string, args ...string) int

异步执行命令行并通过channel返回结果 stdout: chan结果 args: 命令行参数 return: 进程的pid exception: 协程内的命令行发生错误时,会panic异常

func (*LinuxCommand) ExecIgnoreResult

func (lc *LinuxCommand) ExecIgnoreResult(args ...string) error

执行命令行(忽略返回值) args: 命令行参数 return: 错误消息

type WindowsCommand

type WindowsCommand struct {
}

WindowsCommand结构体

func NewWindowsCommand

func NewWindowsCommand() *WindowsCommand

WindowsCommand的初始化函数

func (*WindowsCommand) Exec

func (lc *WindowsCommand) Exec(args ...string) (int, string, error)

执行命令行并返回结果 args: 命令行参数 return: 进程的pid, 命令行结果, 错误消息

func (*WindowsCommand) ExecAsync

func (lc *WindowsCommand) ExecAsync(stdout chan string, args ...string) int

异步执行命令行并通过channel返回结果 stdout: chan结果 args: 命令行参数 return: 进程的pid exception: 协程内的命令行发生错误时,会panic异常

func (*WindowsCommand) ExecIgnoreResult

func (lc *WindowsCommand) ExecIgnoreResult(args ...string) error

执行命令行(忽略返回值) args: 命令行参数 return: 错误消息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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