cmd

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

README

cmd GoDoc

Functions

exec(command, [timeout=10]) - execute command via exec.Start. Will wait while command is executed. Returns table with values

  • status
  • stdout
  • stderr

The default timeout is 10 seconds after which the command will be terminated. The default timeout may be overriden with an optional timeout value (seconds).

Examples

local cmd = require("cmd")
local runtime = require("runtime")

local command = "sleep 1"
if runtime.goos() == "windows" then command = "timeout 1" end

local result, err = cmd.exec(command)
if err then error(err) end
if not(result.status == 0) then error("status") end
local cmd = require("cmd")
local runtime = require("runtime")

local command = "sleep 5"
if runtime.goos() == "windows" then command = "timeout 1" end

local result, err = cmd.exec(command, 1)
if err then error(err) end
if not(result.status == 0) then error("status") end

Documentation

Overview

Package cmd implements golang cmd functionality for lua.

Index

Examples

Constants

View Source
const (
	//Timeout default execution timeout in seconds
	Timeout = 10
)

Variables

This section is empty.

Functions

func Exec

func Exec(L *lua.LState) int

Exec lua cmd.exec(command) return ({status=0, stdout="", stderr=""}, err)

Example

cmd.exec()

state := lua.NewState()
Preload(state)
runtime.Preload(state)
source := `
local cmd = require("cmd")
local runtime = require("runtime")

local command = "sleep 1"
if runtime.goos() == "windows" then command = "timeout 1" end

local result, err = cmd.exec(command)
if err then error(err) end
print(result.status)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

0

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds cmd to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local cmd = require("cmd")

Types

This section is empty.

Directories

Path Synopsis
glua with preload libs original: https://raw.githubusercontent.com/yuin/gopher-lua/master/cmd/glua/glua.go
glua with preload libs original: https://raw.githubusercontent.com/yuin/gopher-lua/master/cmd/glua/glua.go

Jump to

Keyboard shortcuts

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