Closed Drexel2k closed 2 weeks ago
This is not an issue with $PATH and everything to do with your script/program/program argument using a relative path not an absolute one.
$PATH is used by the shell when searching for programs/application by file name where nothing other than the program name has been given. It has nothing to do with where the program looks for additional files.
Differences between running under the various startup methods and running under a logged in shell have been covered elsewhere in the guide.
Nothing to fix.
Hello,
I think you misunderstood me, I didn't meant the $PATH environment variable.
Within a .desktop file you can define a Path key on the same leve as the Exec key e.g.: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys
This sets the working directory for the binary you want to execute, but on startup/login this setting is ignored.
Best regards Matthias
Interesting. Yes, I did misunderstand. Yes, I've reproduced the behaviour you describe. Happens with both X11 and Wayland/Watfire.
Not sure what further action to take at this time. I would strongly argue that the need for the pwd to be set to the correct thing is a flaw in the program that should be fixed there not by fudging the .desktop file.
After all there is no guarantee that the pwd will be correct when the program is run from a logged in session or other start up method.
Consider:
PWD: /home/pi
Actual program directory: /home/pi/dev
Dependencies: myfile.csv
(by relative path)
$PATH: default
Comand: ~/dev/myscript
Result: program fails as it can't find myfile.csv
Change $PATH to /home/pi/dev:$PATH
Rerun the above command.
Result: as above
Would you advise the user to instead run cd dev ; ./myscript
? Even though it would leave them in a different directory once myscript exits? (Yes, I know cd dev ; ./myscript ; cd -
would get around that but that's not the correct solution either. Neither is wrapping all that into a shell script.)
Plus see 8.3.4 and 8.3.5
I would at least mention the shell commands as a workaround, I think it is not feasable for all programs to work with static paths. I have a GUI program written in Python which can be placed anywhere in the file system and it needs some resources from its directory like icons etc. Maybe I could somehow get the info where it was started from, I have to investigate it further. At least for my case it doesn't matter that the direcory is set, as there are no following actions after the script.
I also thought of opening an issue at LXDE, maybe it can be fixed for the future, in Ubuntu this was also an issue which was fixed sometime.
For python something like this:
import os
my_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(my_dir, 'myfile')) as f:
[...]
Maybe you could add a comment, that the Path key is ignored on startup, when you execute the file manually it works. This is critical for apps which rely on data in the working directory.
Detailed information here: https://forums.raspberrypi.com/viewtopic.php?t=292120
As a workaround you can define a shell script, which first changes the directory and then executes the file, also described in the link above:
Exec=sh -c "cd /home/pi/folder; /home/pi/folder/script"