dpgf42422 2015-11-30 18:57
浏览 101
已采纳

以编程方式在Heroku中运行bash脚本文件

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?

  • 写回答

1条回答 默认 最新

  • ds3422222 2015-11-30 19:20
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵