{"id":19489061,"url":"https://github.com/vladimirvivien/gexe","last_synced_at":"2025-05-16T16:09:11.387Z","repository":{"id":46643043,"uuid":"213283321","full_name":"vladimirvivien/gexe","owner":"vladimirvivien","description":"Script-like system automation wrapped in the security and type safety of the Go programming language","archived":false,"fork":false,"pushed_at":"2025-04-06T16:04:27.000Z","size":205,"stargazers_count":114,"open_issues_count":8,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T15:57:01.599Z","etag":null,"topics":["devops","go","golang","scripting"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vladimirvivien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-10-07T02:57:06.000Z","updated_at":"2025-04-07T12:53:36.000Z","dependencies_parsed_at":"2025-04-03T16:10:28.643Z","dependency_job_id":null,"html_url":"https://github.com/vladimirvivien/gexe","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.021739130434782594","last_synced_commit":"a87a71fd24843b5feedefb14c17bb9cac3fff24d"},"previous_names":["vladimirvivien/echo"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladimirvivien%2Fgexe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladimirvivien%2Fgexe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladimirvivien%2Fgexe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladimirvivien%2Fgexe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vladimirvivien","download_url":"https://codeload.github.com/vladimirvivien/gexe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254564127,"owners_count":22092122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","go","golang","scripting"],"created_at":"2024-11-10T21:07:09.846Z","updated_at":"2025-05-16T16:09:11.368Z","avatar_url":"https://github.com/vladimirvivien.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/vladimirvivien/gexe.svg)](https://pkg.go.dev/github.com/vladimirvivien/gexe)\n[![Go Report Card](https://goreportcard.com/badge/github.com/vladimirvivien/echo)](https://goreportcard.com/report/github.com/vladimirvivien/echo)\n![Build](https://github.com/vladimirvivien/gexe/actions/workflows/build.yml/badge.svg)\n# Project `gexe`\nPackage with script-like API for system operation and automation!\n\nThe goal of project `gexe` is to make it simple to write code for system operation and task automation using a script-like API that offers the security and the type safety of the Go programming language (see [/examples](/examples/)).\n\n\u003e NOTE: this project got renamed from Echo to Gexe (see Project Name Change)\n\n## What can you do with `gexe`?\n* Parse and execute OS plain text commands, as you would in a shell.\n* Support for variable expansion in command string (i.e. `gexe.Run(\"echo $HOME\")`)\n* Ability to pipe processes: `gexe.Pipe(\"cat /etc/hosts\", \"wc -l\")`\n* Run processes concurrently: `gexe.RunConcur('wget https://example.com/files'; \"date\")`\n* Get process information (i.e. PID, status, exit code, etc)\n* Get program information (i.e. args, binary name, working dir, etc)\n* Easily read and write file content using different sources (string, bytes, io.Writer, etc)\n* Integrate with your shell script using `go run`\n\n## Using `gexe`\n\n### Get the package\n```bash\ngo get github.com/vladimirvivien/gexe\n```\n\n### Run a process\nThe following executes command `echo \"Hello World!\"` and prints the result:\n```go\nfmt.Println(gexe.Run(`echo \"Hello World!\"`))\n```\n\nAlternatively, you can create your own `gexe` session for more control and error hanlding:\n\n```go\ng := gexe.New()\nproc := g.RunProc(`echo \"Hello World\"`)\nif proc.Err() != nil {\n    fmt.Println(proc.Err())\n    os.Exit(proc.ExitCode())    \n}\nfmt.Println(proc.Result())\n```\n\n## Examples\nFind more examples [here](./examples/)!\n\n### Building project `$gexe` with `gexe`\nThis example shows how `gexe` can be used to build Go project binaries for multiple\nplatforms and OSes. Note the followings:\n* The command string is naturally expressed as you would in a shell.\n* The use of variable expansion in the commands.\n\n```go\nfunc main() {\n\tfor _, arch := range []string{\"amd64\"} {\n\t\tfor _, opsys := range []string{\"darwin\", \"linux\"} {\n\t\t\tgexe.SetVar(\"arch\", arch).SetVar(\"os\", opsys)\n\t\t\tgexe.SetVar(\"binpath\", fmt.Sprintf(\"build/%s/%s/mybinary\", arch, opsys))\n\t\t\tresult := gexe.Envs(\"CGO_ENABLED=0 GOOS=$os GOARCH=$arch\").Run(\"go build -o $binpath .\")\n\t\t\tif result != \"\" {\n\t\t\t\tfmt.Printf(\"Build for %s/%s failed: %s\\n\", arch, opsys, result)\n\t\t\t\tos.Exit(1)\n\t\t\t}\n\t\t\tfmt.Printf(\"Build %s/%s: %s OK\\n\", arch, opsys, echo.Eval(\"$binpath\"))\n\t\t}\n\t}\n}\n```\n\u003e See [./examples/build/main.go](./examples/build/main.go)\n\n### Long-running process\nThis example shows how `gexe` can be used to launch a long-running process and stream\nits output. The code invokes the `ping` command, streams its output, displays the result,\nand then kills the process after 5 seconds.\n\n```go\nfunc main() {\n\texecTime := time.Second * 5\n\tfmt.Println(\"ping golang.org...\")\n\n\tp := gexe.StartProc(\"ping golang.org\")\n\n\tif p.Err() != nil {\n\t\tfmt.Println(\"ping failed:\", p.Err())\n\t\tos.Exit(1)\n\t}\n\n\tgo func() {\n\t\tif _, err := io.Copy(os.Stdout, p.StdOut()); err != nil {\n\t\t\tfmt.Println(err)\n\t\t\tos.Exit(1)\n\t\t}\n\t}()\n\n\t\u003c-time.After(execTime)\n\tp.Kill()\n\tfmt.Printf(\"Pinged golang.org for %s\\n\", execTime)\n}\n```\n\n### Using a shell\nThis example uses the `git` command to print logs and commit info by using `/bin/sh` to start a shell for command piping:\n\n```go\nfunc main() {\n\tcmd := `/bin/sh -c \"git log --reverse --abbrev-commit --pretty=oneline | cut -d ' ' -f1\"`\n\tfor _, p := range strings.Split(gexe.Run(cmd), \"\\n\") {\n\t\tgexe.SetVar(\"patch\", p)\n\t\tcmd := `/bin/sh -c \"git show --abbrev-commit -s --pretty=format:'%h %s (%an) %n' ${patch}\"`\n\t\tfmt.Println(gexe.Run(cmd))\n\t}\n}\n```\n\n# Project Name Change\nOriginally this project was named `echo`.  However, another Go project by that name has gotten really popular.\nSo this project was renamed `gexe` (pronounced Jesse).\n# License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladimirvivien%2Fgexe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvladimirvivien%2Fgexe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladimirvivien%2Fgexe/lists"}