I've got an electron/node application (editor) that uses a bunch of system commands to interact with a bunch of projects on my computer. So in short, when my application needs some information about those projects (for those interesed, rospack
and rosrun
), it performs a system command (with node
's child_process
and exec
/execSync
). The return code and stdout are then formatted an displayed in the editor. So far so good.
For these commands to be used a certain bash file needs to be sourced. I don't understand why completely but I think mostly because it adds some stuff to the path and it sets two other environment variables that the commands use. I am not entirely sure though; there might be some bash/terminal specific black magic in there (when I don't source the bash and execute the command with an absolute path, it complains about a .so
not being present) but it's very hard for me to find out (for those interested, it's the setup.bash
script from ROS).
Sourcing the bash file usually is no problem; most of my friends and I have it in our .bashrc
so when we launch the editor from the command line it finds the commands and the editor runs smoothly. However, if you launch the application by double-clicking, my .bashrc
is not being sourced (as far as I have been able to tell from eyeballing the internet) . Therefore it cannot find the commands when launched by doubleclicking.
Launching the editor from the command line is acceptable, but I'd like it to be as smooth as can be. So my question is: is there a way to source this bash file before my double clicked application is launched? Things I have tried:
- Ubuntu desktop file in various forms:
Exec="bash -c 'source the_bash.sh; ./editor'"
Exec=source_bash_and_start_editor.sh
- Obviously also
Exec=./editor
, but that certainly didn't work - I've also been having problems with relative paths in the desktop file. With absolute paths it seemed to work (with the second and third approach above), but that's not an acceptable solution since I cannot hardcode the paths.
- Making bash script that sources my
.bashrc
and then executes the editor double-clickable.- This would probably work (not entirely sure though), but then I would have to change some system settings to make the bash script double-clickable. By default double clicking opens the script in a text editor, and I would like to avoid that since everyone is used to that.
- A bash script that sources my
.bashrc
and then executes the editor. This script is executed by thesystem()
C command in a small executable that I could ship with the editor.- I think in this case it can actually execute the command, but then the command can't find the
.so
file. So it seems that the sourcing happened incorrectly/incompletely.
- I think in this case it can actually execute the command, but then the command can't find the
- Sourcing the bash file in my
node
exec
/execSync
calls (i.e.source ~/.bashrc; rospack ...
or. ~/.bashrc; rospack ...
)node
simply said "command not found" or something along those lines
For context, I'm using Ubuntu 16.04, and the Electron version I'm using is v1.4.13.