pull file
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
This commit is contained in:
38
krew/pkg/utils/cmd.go
Normal file
38
krew/pkg/utils/cmd.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func Run(cmd *exec.Cmd, in io.Reader) error {
|
||||
cmd.Stdin = in
|
||||
|
||||
stdoutReader, _ := cmd.StdoutPipe()
|
||||
stdoutScanner := bufio.NewScanner(stdoutReader)
|
||||
go func() {
|
||||
for stdoutScanner.Scan() {
|
||||
fmt.Println(stdoutScanner.Text())
|
||||
}
|
||||
}()
|
||||
stderrReader, _ := cmd.StderrPipe()
|
||||
stderrScanner := bufio.NewScanner(stderrReader)
|
||||
go func() {
|
||||
for stderrScanner.Scan() {
|
||||
fmt.Println(stderrScanner.Text())
|
||||
}
|
||||
}()
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return GenErrorMsg(EXEC_ERROR, err.Error())
|
||||
}
|
||||
|
||||
// Stuck here until there are out and err
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return GenErrorMsg(EXEC_ERROR, err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user