从PHP的shell_exec()函数执行Golang二进制文件

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.

shell_exec function Maybe require password of sudo ,

Linux pipe for sudo password

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


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.