@@ -3,7 +3,7 @@ package commands
33import (
44 "context"
55 "fmt"
6- "io/ioutil "
6+ "io"
77 "os"
88 "os/exec"
99 "path/filepath"
@@ -87,7 +87,7 @@ func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error {
8787// ExecutableFromString takes a string like `docker ps -a` and returns an executable command for it
8888func (c * OSCommand ) ExecutableFromString (commandStr string ) * exec.Cmd {
8989 splitCmd := str .ToArgv (commandStr )
90- return c .command (splitCmd [0 ], splitCmd [1 :]... )
90+ return c .NewCmd (splitCmd [0 ], splitCmd [1 :]... )
9191}
9292
9393// Same as ExecutableFromString but cancellable via a context
@@ -96,6 +96,12 @@ func (c *OSCommand) ExecutableFromStringContext(ctx context.Context, commandStr
9696 return exec .CommandContext (ctx , splitCmd [0 ], splitCmd [1 :]... )
9797}
9898
99+ func (c * OSCommand ) NewCmd (cmdName string , commandArgs ... string ) * exec.Cmd {
100+ cmd := c .command (cmdName , commandArgs ... )
101+ cmd .Env = os .Environ ()
102+ return cmd
103+ }
104+
99105func (c * OSCommand ) NewCommandStringWithShell (commandStr string ) string {
100106 var quotedCommand string
101107 // Windows does not seem to like quotes around the command
@@ -187,12 +193,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) {
187193 return nil , errors .New ("No editor defined in $VISUAL or $EDITOR" )
188194 }
189195
190- return c .PrepareSubProcess (editor , filename ), nil
191- }
192-
193- // PrepareSubProcess iniPrepareSubProcessrocess then tells the Gui to switch to it
194- func (c * OSCommand ) PrepareSubProcess (cmdName string , commandArgs ... string ) * exec.Cmd {
195- return c .command (cmdName , commandArgs ... )
196+ return c .NewCmd (editor , filename ), nil
196197}
197198
198199// Quote wraps a message in platform-specific quotation marks
@@ -239,7 +240,7 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
239240
240241// CreateTempFile writes a string to a new temp file and returns the file's name
241242func (c * OSCommand ) CreateTempFile (filename , content string ) (string , error ) {
242- tmpfile , err := ioutil . TempFile ("" , filename )
243+ tmpfile , err := os . CreateTemp ("" , filename )
243244 if err != nil {
244245 c .Log .Error (err )
245246 return "" , WrapError (err )
@@ -301,7 +302,7 @@ func (c *OSCommand) GetLazydockerPath() string {
301302
302303// RunCustomCommand returns the pointer to a custom command
303304func (c * OSCommand ) RunCustomCommand (command string ) * exec.Cmd {
304- return c .PrepareSubProcess (c .Platform .shell , c .Platform .shellArg , command )
305+ return c .NewCmd (c .Platform .shell , c .Platform .shellArg , command )
305306}
306307
307308// PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
@@ -341,7 +342,7 @@ func (c *OSCommand) PipeCommands(commandStrings ...string) error {
341342 c .Log .Error (err )
342343 }
343344
344- if b , err := ioutil .ReadAll (stderr ); err == nil {
345+ if b , err := io .ReadAll (stderr ); err == nil {
345346 if len (b ) > 0 {
346347 finalErrors = append (finalErrors , string (b ))
347348 }
0 commit comments