digitalmars.D.learn - Calling executable generated by dub with sudo
- Selim Ozel (7/7) Dec 07 2020 Let's say I build my package using dub run from an Ubuntu
- Paul Backus (12/19) Dec 07 2020 Something like this, I guess:
- Selim Ozel (15/22) Dec 08 2020 My solution has been slightly different. I use postBuildCommands
Let's say I build my package using dub run from an Ubuntu terminal. How can I add sudo as the executable is being run? I tried adding preRunCommands to my dub.sdl as described in [1] but that just runs sudo and terminal throws an error. Best, Selim [1] https://dub.pm/package-format-sdl
Dec 07 2020
On Monday, 7 December 2020 at 20:34:36 UTC, Selim Ozel wrote:Let's say I build my package using dub run from an Ubuntu terminal. How can I add sudo as the executable is being run? I tried adding preRunCommands to my dub.sdl as described in [1] but that just runs sudo and terminal throws an error. Best, Selim [1] https://dub.pm/package-format-sdlSomething like this, I guess: import core.sys.posix.unistd: getuid; import std.process: execv; void main(string[] args) { if (getuid() != 0) { execv("sudo", args); return 1; // failed to exec } // The rest of your code goes here }
Dec 07 2020
On Monday, 7 December 2020 at 20:34:36 UTC, Selim Ozel wrote:Let's say I build my package using dub run from an Ubuntu terminal. How can I add sudo as the executable is being run? I tried adding preRunCommands to my dub.sdl as described in [1] but that just runs sudo and terminal throws an error. Best, Selim [1] https://dub.pm/package-format-sdlMy solution has been slightly different. I use postBuildCommands and use dub build package:example_backend at my terminal instead of dub run package:example_backend. subPackage { name "example_backend" sourcePaths "source/example_backend" "lib" importPaths "lib" targetName "example_backend" targetType "executable" dependency "mysql-native" version="~>2.2.2" postBuildCommands "sudo ./example_backend" } Best, Selim
Dec 08 2020