mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-29 04:49:39 -08:00
feat(shell): add a CLI timeout of 4 seconds
resolves 3332
This commit is contained in:
parent
5eb6e99ea3
commit
cd4ca2bdf4
|
@ -2,12 +2,18 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Run is used to correctly run a command with a timeout.
|
||||||
func Run(command string, args ...string) (string, error) {
|
func Run(command string, args ...string) (string, error) {
|
||||||
cmd := exec.Command(command, args...)
|
// set a timeout of 4 seconds
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, command, args...)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
var err bytes.Buffer
|
var err bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
|
|
Loading…
Reference in a new issue