Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The output pane always shows fork/exec : no such file or directory #1

Closed
neilco opened this issue May 20, 2021 · 5 comments
Closed

Comments

@neilco
Copy link

neilco commented May 20, 2021

Summary:

The output pane always shows fork/exec : no such file or directory.

Steps to Reproduce:

  • Download the v0.1.0 DMG
  • Install Ginker into /Applications
  • Run Ginker
  • Set the Golang Binary path to /usr/local/go/bin/go in preferences (because it was empty)
  • Modify the string argument to fmt.Println.

Environment:

  • macOS 11.3.1 (Big Sur)
  • Go 1.16.4 (installed from official package)

Expected Outcome:

  • The output pane shows the modified string

Actual Outcome:

  • The output pane shows fork/exec : no such file or directory.

Nope

@nkoporec
Copy link
Owner

I suspect that the 'Golang binary' path does not work correctly on Mac OS, since it was empty as first. I'm using it on my workstation(linux) and the go path does get populated at startup.I will try to replicate the issue on my mac later in the day.

@neilco
Copy link
Author

neilco commented May 20, 2021

This line shows that the "darwin" case is empty and this explains why the Golang Binary path is empty under macOS. It will not fall through to the "linux" case, which is what I suspect you intend. The right way is shown below:

switch os := runtime.GOOS; os {
case "darwin":
  fallthrough
case "linux":
  cmd := exec.Command("which", "go")
  stdout, err := cmd.Output()

  if err != nil {
  }
  goBinary = string(stdout)
}

An alternative approach is shown here:

switch os := runtime.GOOS; os {
case "darwin", "linux":
  cmd := exec.Command("which", "go")
  stdout, err := cmd.Output()

  if err != nil {
  }
  goBinary = string(stdout)
}

@nkoporec
Copy link
Owner

Yep you were right, the switch case was ignored. I published a new release where this is fixed + the gobinary path should also work now.

Let me know, if it works.

@neilco
Copy link
Author

neilco commented May 21, 2021

I removed my Ginker config (rm -rf ~/.ginker) and ran v0.1.1. The issue remained, so I did some digging...

Fun fact: Forking a child process from within macOS app bundle does not inherit the environment of the user that launched the app bundle 🤦

I got it working by appending $GOROOT/bin to $PATH:

switch runtime.GOOS {
case "darwin", "linux":
  // Configure $PATH with a sensible default
  defaultGoBin := filepath.Clean(path.Join(runtime.GOROOT(), "bin"))
  os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), defaultGoBin))
  
  cmd := exec.Command("which", "go")
  stdout, err := cmd.Output()

  if err != nil {
  }
  goBinary = string(stdout)
}

A safer approach would be this:

switch runtime.GOOS {
case "darwin", "linux":  
  cmd := exec.Command("which", "go")
  stdout, err := cmd.Output()

  if err != nil {
  }
  goBinary = string(stdout)
  if goBinary == "" && runtime.GOROOT() != "" {
    goBinary = filepath.Clean(path.Join(runtime.GOROOT(), "bin", "go"))
  }
}

@nkoporec
Copy link
Owner

Nice, did not think of running the app inside the app bundle. I committed your suggestions to the master branch 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants