https://github.com/codeskyblue/kexec
Killable os/exec for golang library.
https://github.com/codeskyblue/kexec
Last synced: about 1 year ago
JSON representation
Killable os/exec for golang library.
- Host: GitHub
- URL: https://github.com/codeskyblue/kexec
- Owner: codeskyblue
- License: mit
- Created: 2015-11-11T01:51:40.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-01-19T01:57:32.000Z (over 8 years ago)
- Last Synced: 2025-03-18T11:05:39.923Z (over 1 year ago)
- Language: Go
- Size: 443 KB
- Stars: 21
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kexec
[](https://godoc.org/github.com/codeskyblue/kexec)
This is a golang lib, add a `Terminate` command to exec.
Tested on _windows, linux, darwin._
This lib has been used in [fswatch](https://github.com/codeskyblue/fswatch).
## Usage
```
go get -v github.com/codeskyblue/kexec
```
example1:
```go
package main
import "github.com/codeskyblue/kexec"
func main(){
p := kexec.Command("python", "flask_main.py")
p.Start()
p.Terminate(syscall.SIGINT)
}
```
example2: see more [examples](examples)
```go
package main
import (
"github.com/codeskyblue/kexec"
)
func main() {
// In unix will call: bash -c "python flask_main.py"
// In windows will call: cmd /c "python flask_main.py"
p := kexec.CommandString("python flask_main.py")
p.Stdout = os.Stdout
p.Stderr = os.Stderr
p.Start()
p.Terminate(syscall.SIGKILL)
}
```
example3:
```go
package main
import "github.com/codeskyblue/kexec"
func main() {
p := kexec.Command("whoami")
p.SetUser("codeskyblue") // Only works on darwin and linux
p.Run()
}
```
## Command line usage
```
$ go get -v github.com/codeskyblue/kexec/cmds/kexec
$ kexec python main.py
# Ctrl+C
python is terminating ...
```
## PS
This lib also support you call `Wait()` twice, which is not support by `os/exec`
## LICENSE
[MIT](LICENSE)