dow57588
dow57588
2018-01-10 20:37

从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 3年前

    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 3年前

    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()
    
    点赞 评论 复制链接分享

相关推荐