xbar: Interpreted Go exec format error

I have a Go file that starts with:

//path/to/go run $0 $@; exit

In the plugin browser, it looks good, all the metadata is interpreted correctly and the variable shows up editable as expected, but the plugin won’t run. I get the error fork/exec ./001-myplugin.1h.go: exec format error.

When I run the plugin in the terminal with ./ it runs fine. I’ve run chmod +X as well, still getting the error.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (6 by maintainers)

Most upvoted comments

Sorted?

image

// is not a valid shebang (needs to be #!) and therefore not used by the kernel for exec-ing the interpreter. When executed with a shell, the first line just runs the command the path points to (for example /usr/local/bin/go or /usr/bin/true; exec /usr/bin/env go run "$0" "$@". Double slashes just get ignored. If you use ///bin/echo Hi there in the first line, and run it from a shell, you’ll notice it just prints “Hi there” and runs the rest of the script.

If you don’t mind spawning an extra process, starting it from a shell might be a solution: cmd := exec.CommandContext(ctx, "sh",command).

Edit: Ah, just noticed you got some good feedback on Twitter already. My bad, I might have jumped too eagerly on this nice little puzzle. Anyway, I learned some stuff, so I’m happy.

Hi John, as a workaround, I started putting my go scripts in a go directory inside the plug-in directory.

As an example, ~/Library/Application Support/xbar/plugin/my-plugin.10s contains:

#!/bin/sh
exec /usr/local/bin/go run go/$0.go $@

Which would run ~/Library/Application Support/xbar/plugin/go/my-plugin.10s.go.

Edit: I’d like to point out that the workaround I mentioned is flawed too. According to the docs, the name of the plugin should be in the form {name}.{time}.{ext} and the way I did it, I left out the .{ext} part. As a result, it will not run at the desired interval.