1

I have a web app written in Go and deployed on Heroku. Recently, I've implemented a new feature that needs to run a bash script file and retrieve its output. The command I'm using is:

out, err := exec.Command("bash", script_path, arg).Output()

Where script_path is the absolute path to the script. (which is built dynamically by using the caller filepath) And arg is an input to the script.

This command works fine in my local machine but not in Heroku:

18:51:40 http: panic serving 10.238.8.204:17763: exit status 127

ps: If I run the same command on "heroku run bash", it works.

Any thoughts?

7
  • Have you fixed you issue? Commented Feb 1, 2016 at 22:20
  • Yes. It's working with the full path to bash executable: out, err := exec.Command("/bin/bash", script_path, arg).Output() Commented Feb 2, 2016 at 0:38
  • Ok, so, I should do something wrong on my side! Thanks for the feedback and confirming that it is possible to do it! Commented Feb 2, 2016 at 8:29
  • Does your script_path looks like /app/path/to/script.sh ? It's annoying but I can't get it working whereas it works when using heroku run bash... Commented Feb 2, 2016 at 17:58
  • yes: script_path := path.Join(".", "src", "ext", "dextenso.sh") Commented Feb 2, 2016 at 21:49

1 Answer 1

1

a shell return code of 127 is to designate "Command not found".

You can see this behavior with this small example.

$ nonesuch
-bash: nonesuch: command not found
$ echo $?
127

This sort of issue usually means you need to add

 /full/path/to/myscriptdir

to the PATH env var. i.e.

 export PATH="$PATH:/full/path/to/myscriptdir withSpaces" 

There are several places this can be accomplished, but it depends on your organizations rules for such things.

To immediately resolve the problem, add to the $HOME/.profile file of the userID that runs Heroku OR there is likely a Heroku specific config file that it could be added to. (I don't have experience w Heroku).

It's interesting that this article Heroku config files doesn't mention PATH variable.


As you have discovered, you can edit your code to include the full path directly, i.e.

out, err := exec.Command("/bin/bash", path.Join(".", "src", "ext", "dextenso.sh"), 

IHTH

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Shelter, you answer helped me to find the solution, but those steps with the PATH variable were not necessary. I just needed to specify the full path to the bash executable and to my script. Like this: out, err := exec.Command("/bin/bash", path.Join(".", "src", "ext", "dextenso.sh"), arg).Output(). Could you edit your answer so I can mark it as the solution? thanks!
@marcelo : Hi, OK, I've done that. I'm glad it helped!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.