-
Notifications
You must be signed in to change notification settings - Fork 47
/
exec.go
61 lines (53 loc) · 1.51 KB
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Copyright (c) 2021 - Present. Blend Labs, Inc. All rights reserved
Use of this source code is governed by a MIT license that can be found in the LICENSE file.
*/
package sh
import (
"context"
"os"
)
// ExecParsed parses a command string into binary and args.
// It resolves the command name in your $PATH list for you.
// It does not show output.
func ExecParsed(command string) error {
cmd, err := CmdParsed(command)
if err != nil {
return err
}
cmd.Env = os.Environ()
return cmd.Run()
}
// ExecParsedContext parses a command string into binary and args within a context.
// It resolves the command name in your $PATH list for you.
// It does not show output.
func ExecParsedContext(ctx context.Context, command string) error {
cmd, err := CmdParsedContext(ctx, command)
if err != nil {
return err
}
cmd.Env = os.Environ()
return cmd.Run()
}
// Exec runs a command with a given list of arguments.
// It resolves the command name in your $PATH list for you.
// It does not show output.
func Exec(command string, args ...string) error {
cmd, err := Cmd(command, args...)
if err != nil {
return err
}
cmd.Env = os.Environ()
return cmd.Run()
}
// ExecContext runs a command with a given list of arguments within a context.
// It resolves the command name in your $PATH list for you.
// It does not show output.
func ExecContext(ctx context.Context, command string, args ...string) error {
cmd, err := CmdContext(ctx, command, args...)
if err != nil {
return err
}
cmd.Env = os.Environ()
return cmd.Run()
}