{"id":36583777,"url":"https://github.com/go-rillas/subprocess","last_synced_at":"2026-01-12T08:00:15.378Z","repository":{"id":49356338,"uuid":"117308040","full_name":"go-rillas/subprocess","owner":"go-rillas","description":"A Go library that returns standard output, standard error, and exit status code data from spawned processes on Linux, macOS, and Windows","archived":false,"fork":false,"pushed_at":"2018-02-04T13:56:07.000Z","size":31,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-27T03:41:54.297Z","etag":null,"topics":["golang","golang-library","subprocess","system"],"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/go-rillas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-13T02:46:36.000Z","updated_at":"2024-04-05T23:42:41.000Z","dependencies_parsed_at":"2022-09-16T03:50:27.694Z","dependency_job_id":null,"html_url":"https://github.com/go-rillas/subprocess","commit_stats":null,"previous_names":["pygz/subprocess"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/go-rillas/subprocess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rillas%2Fsubprocess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rillas%2Fsubprocess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rillas%2Fsubprocess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rillas%2Fsubprocess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-rillas","download_url":"https://codeload.github.com/go-rillas/subprocess/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rillas%2Fsubprocess/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28336957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","golang-library","subprocess","system"],"created_at":"2026-01-12T08:00:12.134Z","updated_at":"2026-01-12T08:00:15.134Z","avatar_url":"https://github.com/go-rillas.png","language":"Go","readme":"# go-rillas/subprocess \n\n[![GitHub release](https://img.shields.io/github/release/go-rillas/subprocess.svg?style=flat-square)](https://github.com/go-rillas/subprocess/releases/latest)\n[![Software License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/gopkg.in/go-rillas/subprocess.v1)\n[![Build Status](https://semaphoreci.com/api/v1/go-rillas/subprocess/branches/master/badge.svg)](https://semaphoreci.com/go-rillas/subprocess)\n[![Build status](https://ci.appveyor.com/api/projects/status/6s0es0a54fs21r71/branch/master?svg=true)](https://ci.appveyor.com/project/chrissimpkins/subprocess/branch/master)\n\n## About\n\nsubprocess is a Go library that returns standard output, standard error, and exit status code data from newly spawned processes on Linux, macOS, and Windows platforms.  It was inspired by the Python subprocess standard library module.\n\nThe subprocess library API is versioned under the [SemVer specification](https://semver.org/).\n\n## Install\n\nThe subprocess package does not include external dependencies. It is built with the Go standard library.\n\nInstall the subprocess library locally for testing and development use with the following command:\n\n```\ngo get gopkg.in/go-rillas/subprocess.v1\n```\n\n## Usage\n\nsubprocess exposes two public functions and a public struct with standard output, standard error, and exit status code data from executable files.  [Full API documentation is available on GoDoc](https://godoc.org/github.com/go-rillas/subprocess).\n\n### Import `subprocess` into your source files\n\n```go\npackage main\n\nimport (\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n```\n\n### Public Data Types\n\n#### `subprocess.Response`\n\nThe subprocess package defines the `Response` public data type with standard output, standard error, and exit status code fields.  This is populated and returned to the calling code when you run an executable file with the public functions that are available in the subprocess package.\n\n```go\ntype Response struct {\n    StdOut   string\n    StdErr   string\n    ExitCode int\n}\n```\n\n### Public Functions\n\n#### `subprocess.Run`\n\n```go\nfunc Run(executable string, args ...string) Response\n```\n\nThe `Run()` function runs an executable file with optional arguments and returns the standard output, standard error, and exit status code data in a `Response` struct.  Include one or more arguments to the executable as additional function parameters.\n\n##### Example on macOS/Linux\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n\nfunc main() {\n    response := Run(\"ls\", \"-l\")\n    // print the standard output stream data\n    fmt.Printf(\"%s\", response.StdOut)\n    // print the standard error stream data\n    fmt.Printf(\"%s\", response.StdErr)\n    // print the exit status code integer value\n    fmt.Printf(\"%d\", response.ExitCode)\n}\n```\n\n##### Example on Windows\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n\nfunc main() {\n    response := Run(\"dir\", \"/AD\")\n    // print the standard output stream data\n    fmt.Printf(\"%s\", response.StdOut)\n    // print the standard error stream data\n    fmt.Printf(\"%s\", response.StdErr)\n    // print the exit status code integer value\n    fmt.Printf(\"%d\", response.ExitCode)\n}\n```\n\n\n#### `subprocess.RunShell()`\n\n```go\nfunc RunShell(shell string, shellflag string, command ...string) Response\n```\n\nThe `RunShell()` function runs an executable file with a shell and returns the standard output, standard error, and exit status code data in a `Response` struct.  The default shell for Linux and macOS platforms is `/bin/sh`.  The default shell for Windows is the `cmd.exe` command prompt. Modify the shell by defining the `shell` function parameter.  A shell flag is included to indicate that the argument that follows is to be executed by the shell.  The default flag on macOS and Linux platforms is `-c`.  On Windows, this is `/C`.  Modify the flag by defining the `shellflag` parameter.  Define the command to be executed as one or more parameters at the end of the function call.\n\n##### Example with the default shell on macOS/Linux\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n\nfunc main() {\n    response := RunShell(\"\", \"\", \"ls\", \"-l\")\n    // print the standard output stream data\n    fmt.Printf(\"%s\", response.StdOut)\n    // print the standard error stream data\n    fmt.Printf(\"%s\", response.StdErr)\n    // print the exit status code integer value\n    fmt.Printf(\"%d\", response.ExitCode)\n}\n```\n\n##### Example with the default shell on Windows\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n\nfunc main() {\n    response := RunShell(\"\", \"\", \"dir\", \"/AD\")\n    // print the standard output stream data\n    fmt.Printf(\"%s\", response.StdOut)\n    // print the standard error stream data\n    fmt.Printf(\"%s\", response.StdErr)\n    // print the exit status code integer value\n    fmt.Printf(\"%d\", response.ExitCode)\n}\n```\n\n##### Example with redefined shell on macOS/Linux\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n\nfunc main() {\n    response := RunShell(\"/usr/local/bin/zsh\", \"\", \"ls\", \"-l\")\n    // print the standard output stream data\n    fmt.Printf(\"%s\", response.StdOut)\n    // print the standard error stream data\n    fmt.Printf(\"%s\", response.StdErr)\n    // print the exit status code integer value\n    fmt.Printf(\"%d\", response.ExitCode)\n}\n```\n\n##### Example with redefined shell on Windows\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"gopkg.in/go-rillas/subprocess.v1\"\n)\n\nfunc main() {\n    response := RunShell(\"bash\", \"-c\", \"ls\", \"-l\")\n    // print the standard output stream data\n    fmt.Printf(\"%s\", response.StdOut)\n    // print the standard error stream data\n    fmt.Printf(\"%s\", response.StdErr)\n    // print the exit status code integer value\n    fmt.Printf(\"%d\", response.ExitCode)\n}\n```\n\n### Contributing\n\nContributions to the project are welcomed. Please submit changes in a pull request on the Github repository.\n\n### Testing\n\n[climock](https://github.com/chrissimpkins/climock) is a dependency that must be installed manually for the execution of subprocess package tests.\n\nInstall `climock` with:\n\n```\n$ go get -u github.com/chrissimpkins/climock\n```\n\nYou can then execute source code unit tests and obtain source code coverage data locally by downloading the source repository and executing the following command in the root of the source repository:\n\n```\n$ go test -v -cover ./...\n```\n\nGo must be installed on your system to execute this command.\n\nWe test the subprocess package with [Semaphore CI](https://semaphoreci.com/go-rillas/subprocess) (Linux) and [Appveyor CI](https://ci.appveyor.com/project/chrissimpkins/subprocess) (Windows). You may view the test results following the most recent commit (including commits proposed through a pull request) using those links.\n\n### Acknowledgments\n\nThe subprocess library was inspired by the Python standard library subprocess module.  Source code for the exit status code retrieval was based on source discussed in the Stack Overflow posts [here](https://stackoverflow.com/a/40770011) and [here](https://stackoverflow.com/a/10385867). A big thanks to Michael ([@texhex](https://github.com/texhex)) and JM ([@jublo](https://github.com/jublo)) for their input and feedback on the Windows platform support.\n\n### License\n\nThe subprocess library is licensed under the [MIT license](LICENSE).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-rillas%2Fsubprocess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-rillas%2Fsubprocess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-rillas%2Fsubprocess/lists"}