Home > front end >  fork/exec ./node_modules/.bin/solcjs: no such file or directory
fork/exec ./node_modules/.bin/solcjs: no such file or directory

Time:12-08

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?

CodePudding user response:

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()
  • Related