dow57588
dow57588
2018-01-10 20:37
浏览 156

从golang程序安装npm

I need to run npm install on folder that I was created

Im doing the following

command := exec.Command("../app/node/", "npm", "install")
command.Dir = "."
output, err := command.Output()
if err != nil {
    log.Println(err)
}
fmt.Printf("%s", output)

And I get error :

fork/exec ../app/node/: permission denied

Any idea how to overcome this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanfei1975
    duanfei1975 2018-01-10 20:45
    已采纳

    You've got your arguments to Command in the wrong order. Per the documentation, the first argument is the program to be executed (i.e. npm), the following arguments are the parameters to pass, in the order that command should receive them, e.g.:

    command := exec.Command("npm", "install", "../app/node/")
    
    点赞 评论
  • douqiao5552
    douqiao5552 2018-01-12 10:29

    The format for executing a command using Command is as follows c := exec.Command(<command>,<args>...) In your case the command is npm. Therefore the code should be like the following and you can bind stdout and stderr of the command to shell.So that you can view npm logs.

    command := exec.Command("../app/node/npm","install")
    command.Stdout = os.Stdout
    command.Stderr = os.Stderr
    // Run the command
    command.Run()
    
    点赞 评论

相关推荐