英文:
fork/exec ./node_modules/.bin/solcjs: no such file or directory
问题
我在尝试运行这段代码时遇到了一个小问题。
package main
import (
"fmt"
"os/exec"
)
func main() {
out, err := exec.Command("./node_modules/.bin/solcjs", "--version").Output()
if err != nil {
panic(err)
}
fmt.Println(out)
}
这段代码将从./node_modules/.bin/solcjs
获取solcjs版本。但是,代码返回一个错误,告诉我文件/文件夹不存在,而且我自己尝试了命令./node_modules/.bin/solcjs --version
,它完全正常工作。为什么我使用go时会显示错误?
英文:
I have a small issue here when I try to run this code
package main
import (
"fmt"
"os/exec"
)
func main() {
out, err := exec.Command("./node_modules/.bin/solcjs", "--version").Output()
if err != nil {
panic(err)
}
fmt.Println(out)
}
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
之前添加这个路径:
mydir, _ := os.Getwd()
file_full_path := mydir + "/node_modules/.bin/solcjs"
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
:
mydir, _ := os.Getwd()
file_full_path := mydir + "/node_modules/.bin/solcjs"
out, err := exec.Command(file_full_path, "--version").Output()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论