GoLang os.Chdir() permission denied

WBOY
Release: 2024-02-06 09:24:13
forward
401 people have browsed it

GoLang os.Chdir() 权限被拒绝

Question content

I'm writing a program that creates a directory and then changes the working directory to the newly created directory to perform some work:

func main() {
    err := os.mkdir("english", 0777) // i know 777 is not good practice, first i want to get chdir() working
    if err != nil && !os.isexist(err) {
        log.fatal(err)
    }
    err = os.chdir("english")
    if err != nil {
        log.fatal(err)
    }
}
Copy after login

Console output:

023/02/05 18:15:45 chdir English: permission denied
exit status 1
Copy after login

Correct answer


Simple fix: Executing the program with sudo causes the directory to be created with the specified permissions.

The above is the detailed content of GoLang os.Chdir() permission denied. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!