demo:command run
This commit is contained in:
18
_demo/commandrun/commandrun.go
Normal file
18
_demo/commandrun/commandrun.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var data bytes.Buffer
|
||||||
|
cmd := exec.Command("echo", "hello llgo")
|
||||||
|
cmd.Stdout = &data
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
println("len:", len(data.Bytes()))
|
||||||
|
println("data:", data.String())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user