# Command

### Call System Command

```go
package main

import (
   "context"
   "fmt"
   helper_command "github.com/langwan/langgo/helpers/command"
)

func main() {
   output, err := helper_command.Execute(context.Background(), "ls", []string{"-la"}...)
   if err != nil {
      panic(err)
   }
   fmt.Println(string(output))
}
```

{% code title="output" %}

```shell
total 8
drwxr-xr-x  3 langwan  staff   96 Dec  7 04:47 .
drwxr-xr-x  3 langwan  staff   96 Dec  7 04:44 ..
-rw-r--r--  1 langwan  staff  269 Dec  7 04:47 main.go
```

{% endcode %}

{% embed url="<https://github.com/langwan/langgo-examples/tree/main/0.5.x/Helpers/Command/System>" %}

### Call Outside Command

{% code title="main.go" %}

```go
package main

import (
   "context"
   "fmt"
   helper_command "github.com/langwan/langgo/helpers/command"
)

func main() {
   output, err := helper_command.Execute(context.Background(), "/Users/langwan/go/go1.19.1/bin/go", []string{"help"}...)
   if err != nil {
      panic(err)
   }
   fmt.Println(string(output))
}
```

{% endcode %}

{% code title="output" overflow="wrap" %}

```shell
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        work        workspace maintenance
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        gopath-get      legacy GOPATH go get
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-get      module-aware go get
        module-auth     module authentication using go.sum
        packages        package lists and patterns
        private         configuration for downloading non-public code
        testflag        testing flags
        testfunc        testing functions
        vcs             controlling version control with GOVCS

Use "go help <topic>" for more information about that topic.

```

{% endcode %}

{% embed url="<https://github.com/langwan/langgo-examples/tree/main/0.5.x/Helpers/Command/Outside>" %}
