Documentation ¶
Overview ¶
Package byteexec provides a very basic facility for running executables supplied as byte arrays, which is handy when used with github.com/jteeuwen/go-bindata.
byteexec works by storing the provided command in a file.
Example Usage:
programBytes := // read bytes from somewhere be, err := byteexec.New(programBytes, "new/path/to/executable") if err != nil { log.Fatalf("Uh oh: %s", err) } cmd := be.Command("arg1", "arg2") // cmd is an os/exec.Cmd err = cmd.Run()
Note - byteexec.New is somewhat expensive, and Exec is safe for concurrent use, so it's advisable to create only one Exec for each executable.
Index ¶
Constants ¶
const NewFileMode os.FileMode = 0744
NewFileMode is the mode assigned to files passed to New.
Variables ¶
This section is empty.
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
Types ¶
type Exec ¶
type Exec struct {
Filename string
}
Exec is a handle to an executable that can be used to create an exec.Cmd using the Command method. Exec is safe for concurrent use.
func Existing ¶
Existing is like New, but specifically for programs which already exist in the given file. This can be useful for situations in which it is important that the file not be modified (New can affect file permissions even when the file is not overwritten).
If the path given is a relative path, the executable is assumed to be in one of the following locations:
On Windows - %APPDATA%/byteexec On OSX - ~/Library/Application Support/byteexec All Others - ~/.byteexec
func New ¶
New creates a new Exec using the program stored in the provided data, at the provided filename (relative or absolute path allowed). If the path given is a relative path, the executable will be placed in one of the following locations:
On Windows - %APPDATA%/byteexec On OSX - ~/Library/Application Support/byteexec All Others - ~/.byteexec
Creating a new Exec can be somewhat expensive, so it's best to create only one Exec per executable and reuse that.
WARNING:
- If a file already exists at this location and its contents differ from data, Exec will attempt to overwrite it.
- Even when the file contents match the input data, the file mode will be changed to NewFileMode.