找不到 ./node_modules/.bin/solcjs 文件或目录。

huangapple go评论124阅读模式
英文:

fork/exec ./node_modules/.bin/solcjs: no such file or directory

问题

我在尝试运行这段代码时遇到了一个小问题。

  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. )
  6. func main() {
  7. out, err := exec.Command("./node_modules/.bin/solcjs", "--version").Output()
  8. if err != nil {
  9. panic(err)
  10. }
  11. fmt.Println(out)
  12. }

这段代码将从./node_modules/.bin/solcjs获取solcjs版本。但是,代码返回一个错误,告诉我文件/文件夹不存在,而且我自己尝试了命令./node_modules/.bin/solcjs --version,它完全正常工作。为什么我使用go时会显示错误?

英文:

I have a small issue here when I try to run this code

  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. )
  6. func main() {
  7. out, err := exec.Command("./node_modules/.bin/solcjs", "--version").Output()
  8. if err != nil {
  9. panic(err)
  10. }
  11. fmt.Println(out)
  12. }

This code will get solcjs version from ./node_modules/.bin/solcjs.
But, the code return an error telling me that the file/folder doesn't exist, and I try the command ./node_modules/.bin/solcjs --version my self and it work perfectly. Why when i use go it show error?

答案1

得分: 0

你可能需要提及 solcjs 文件的完整路径。
使用下面的代码片段获取当前工作目录,然后在 /node_modules/.bin/solcjs 之前添加这个路径:

  1. mydir, _ := os.Getwd()
  2. file_full_path := mydir + "/node_modules/.bin/solcjs"
  3. out, err := exec.Command(file_full_path, "--version").Output()
英文:

You probably need to mention the full path of the solcjs file.
Use snippet below to take the current working directory and then add this path before /node_modules/.bin/solcjs:

  1. mydir, _ := os.Getwd()
  2. file_full_path := mydir + "/node_modules/.bin/solcjs"
  3. out, err := exec.Command(file_full_path, "--version").Output()

huangapple
  • 本文由 发表于 2021年12月7日 15:39:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/70256450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定