0

I have compiled a golang binary that takes 1 argument, generates a PDF file, and then uploads it to AWS S3. The binary works perfectly in the shell, however when trying to execute it using PHP's shell_exec(), exec(), passthru() and service() functions, it will not execute (no error messages or log entries). I have even tried calling a shell script (.sh) from PHP's shell_exec which executes the binary (also works fine in the shell), but to no avail.

Permissions are fine and PHP's shell_exec() works for all other instances.

Jamie_D
  • 979
  • 6
  • 13
  • 1
    If you see no error messages, how do you know it didn't execute? No news is good news, no? – Peter Sep 13 '19 at 12:51
  • :) The golang binary displays all AWS upload output (ETAG) so even when I `echo shell_exec(/path/to/binary)` it should output a response – Jamie_D Sep 13 '19 at 12:55
  • Have you tried to add `2>&1` at the end of your command? For instance, if your command is: `shell_exec('your_script.sh');` it would become `shell_exec('your_script.sh 2>&1');` – mdexp Sep 13 '19 at 13:34
  • @mdexp Just tried different variations to your suggestion but no luck yet – Jamie_D Sep 13 '19 at 14:03
  • 1
    pls provide execution string which is used in php-script – myxaxa Sep 13 '19 at 15:13
  • Maybe require sudo pass to exec to shell_exec ,are you sure ? – dılo sürücü Sep 13 '19 at 15:35

2 Answers2

0

shell_exec function Maybe require password of sudo ,

Linux pipe for sudo password

shell_exec('echo "YOURPASS" | sudo -u root -S your_script.sh');


dılo sürücü
  • 3,821
  • 1
  • 26
  • 28
0

It seems I found my own answer:

It turns out that the GoLang binary was having issues finding assets associated with the directory path of the binary file itself. For anyone having these same issues it turns out that @Intermernet answer will help you a great deal. (Please note that @Intermernet's answer is not the accepted answer)

In my case, the compiled binary was not able to locate assets (pdf, images etc) from the executable working directory.

For anyone compiling a portable golang binary that needs to keep track of assets, the following code will be your friend:

ex, err := os.Executable()
if err != nil {
    panic(err)
}
exPath := filepath.Dir(ex)

Note that exPath will not be the same between the go run and go build. So you need to test with the build version.

Why I did not get any error messages I'll reserve for another question on my part.

Jamie_D
  • 979
  • 6
  • 13