Home > Software engineering >  exec: "dir": executable file not found in %PATH%
exec: "dir": executable file not found in %PATH%

Time:01-30

cmd := exec.Command("cd", "..")
err := cmd.Start()
if err != nil {
    fmt.Println(err.Error())
    return
}

i use os/exec by document,but all command cannot be used. Error:exec: [commandname]: executable file not found in %PATH%

win11,golang 1.16.5

CodePudding user response:

The cd command is builtin to the shell. It is not a standalone executable that can be exec’ed.

Use os.Chdir to change the current working directory of the current process.

CodePudding user response:

cmd := exec.Command("copy", "main.go", "..")
    err := cmd.Start()
    if err != nil {
        fmt.Println(err.Error())
        return
    }

exec: "copy": executable file not found in %PATH%

  •  Tags:  
  • Related