2

I have a binary executable file with libraries and I need to embed them all to a golang app, and run the binary via os/exec as a new process from the app. The app runs on Linux with all necessary rights.

How to launch the binary itself, with libraries and arguments, and create a new process? The best, without creating any temporary files.

kajaptz
  • 313
  • 1
  • 4
  • 12
  • 3
    Possibly related to [https://stackoverflow.com/questions/44653960/how-can-i-execute-an-executable-from-memory](https://stackoverflow.com/questions/44653960/how-can-i-execute-an-executable-from-memory) – putu Jun 30 '17 at 08:13
  • Let's skip an easy part, and say that the binary and libraries are defined in `[]byte` variables. The key question is how to lunch the binaries as a new process from the app, e.g. via `os/exec.Command()` resp. how to pass binaries in the variables to the `Command()`. Thank you. – kajaptz Jun 30 '17 at 08:29
  • 1
    exec.Command() call exec(2). You can't execute commands embeded in the binary directly. It must be a file. So it should be extracted command from the binary. – mattn Jun 30 '17 at 08:39
  • @mattn you are right. Note: `os.StartProcess()` is a low-level interface. The `os/exec` package provides just higher-level interfaces. Both start _the program_, an executable binary located in the disk. – kajaptz Jun 30 '17 at 08:53
  • Each of these questions has been answered on stackoverflow and well documented. What have you tried and what's not working? https://stackoverflow.com/questions/13904441/whats-the-best-way-to-bundle-static-resources-in-a-go-program – WiredPrairie Jun 30 '17 at 10:36
  • Possible duplicate of [How can i execute an executable from memory?](https://stackoverflow.com/questions/44653960/how-can-i-execute-an-executable-from-memory) – Adrian Jun 30 '17 at 13:12
  • Were you able to figure this out? Could you share the solution? – user1892775 Nov 26 '18 at 19:24

0 Answers0