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