Thanks anyone to have participate to this question.
I have solved this issue by implemented use of pkexec
instead of gksudo
.
pkexec
seems to reuse the current user environment then I don't have this issue anymore.
Thanks.
質問
I have a python script file that works perfectly when I use it from the terminal.
Now I have created the following .desktop
file in order to launch it easily:
[Desktop Entry]
Name=Test
GenericName=Test
Comment=My test script
Type=Application
Exec=/opt/test.py
Icon=/opt/test.png
Categories=Utils;
When I launch it the GTK window appear but clicking a button that call an init.d script make it working not properly.
Therefore adding Terminal=true
make it working perfectly but I don't want to have that terminal open.
So I have then put the following code in order to log the environment variables:
import os
with open("/tmp/py_env.log", "w") as env_log:
env_log.write(str(os.environ))
and found differences.
So my question is how to write the .desktop file so that my application is running like if I start it from my terminal (without having an opened terminal :))
解決 3
Thanks anyone to have participate to this question.
I have solved this issue by implemented use of pkexec
instead of gksudo
.
pkexec
seems to reuse the current user environment then I don't have this issue anymore.
Thanks.
他のヒント
The problem is valid, but I think "replicating the terminal environment" is the wrong approach to solve it.
Indeed, what makes the application work is not the fact that it's launched from the terminal, it's that the terminal happens to have some environment variables which matter to your application.
Therefore, what you should aim for is to have those environment variables set properly at all times, rather than assuming the terminal environment will always happen to contain them all the time for all your users.
Thus, you should:
.desktop
file work properly), and of what their value needs to be for the script to workthis question is similar to .bashrc not read when shell script is invoked from desktop shortcut
~/.bash_profile
instead of
~/.bashrc
OR
*.desktop
file call a wrapper that initializes your
environment - e.g. by sourcing ~/.bashrc
(or whatever script is
responsible now).the second solution is more specific (does not effect all other unrelated launches of your shell) in should thus be preferred.