{"repo":"go-cmd/cmd","free":true,"listed":false,"github":"https://github.com/go-cmd/cmd","clone":"git clone https://github.com/go-cmd/cmd.git","description":"Non-blocking external commands in Go with streaming output","language":"Go","stars":1026,"topics":["golang","command","asynchronous","real-time","non-blocking"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"go-cmd/Cmd This package is a small but very useful wrapper around os/exec.Cmd that makes it safe and simple to run external commands in highly concurrent, asynchronous, real-time applications. It works on Linux, macOS, and Windows. Here's the basic usage: That's it, only three methods: Start , Stop , and Status . When possible, it's better to use go-cmd/Cmd than os/exec.Cmd because go-cmd/Cmd provides: 1. Channel-based fire and forget 1. Real-time stdout and stderr 1. Real-time status 1. Complete and consolidated return 1. Proper process termination 1. 100% test coverage, no race conditions Channel-based fire and forget As the example above shows, starting a command immediately returns a channel to which the final status is sent when the command exits for any reason. So by default commands run asynchronously, but running synchronously is possible and easy, too: To achieve similar with os/exec.Cmd requires everything this package already does. Real-time stdout and stderr It's common to want to read stdout or stderr while the command is running. The common approach is to call StdoutPipe and read from the provided io.ReadCloser . This works but it's wrong because it causes a race condition (that go test -race detects) and the docs say it's wrong: It is thus incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to call Run when using StdoutPipe. The proper solution is to set the io.Writer of Stdout . To be thread-safe and non-r","default_branch":null,"files":null,"tree":[],"storefront":"/r/go-cmd","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/go-cmd/cmd/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}