I have a python app, which should run a bash script if a specific button is clicked. I put the app into menu, created the .desktop file, everything looks fine except that subprocess.call. I also tried it with os.system(), and several other solution, all of them working properly, if the app is started from terminal, but not, if it's started by its menu icon. Anyone know how to fix this? I want it to run without terminal window, from menu, but couldnt find a topic similar to mine
3 Answers
Okay, both answers work, because the problem was not with the missing terminal, but ME.
I left a code session in my app, which was originally intended to call the script execution, but it was called from another section, so there fixing the relative path
subprocess.call('./script')
to
subprocess.call('absolute_path_to_script')
- this made it immediately. I also tried to change to the absolute path, but the button never invoked that event so... my mistake, thanks for your time to try to help me
3 Comments
That is because GUI processes are detached from stdout/stderr and redirected to loging instead. Please explain what is your bash script doing, and, well, it is run without window, obviously. To check, make it write something to some file, and you will see that the script has been run. Or you refer that you don't like your process to have a console window, but your bash script should be run in one.
If so, make subprocess.call() call terminal first, with command to call bash script.
Please be more precise and explain clearly what you need so that we may help you.
If you really need a terminal to be started, I put together some code for you.
Problem with starting new terminal on Linux is that there are many different desktop environments.
Each of them usually carying its own terminal program.
Which one to use??? You may simply try until you succeed:
import subprocess
script = "~/full_path_to_your_bash_script.sh"
# Uncomment following line to ensure execution by bash and remove potential problems with permissions.
#script = "bash "+script
# Commands to call (add some more if you remember any):
commands = [
['gnome-terminal', '-x', script],
# xterm is usually present:
['xterm', '-e', script],
['rxvt', '-e', script]
]
ok = 0
for command in commands:
try:
subprocess.call(command)
ok = 1; break
except OSError, e:
if e.errno==2: continue # No such file or directory - skip non-existing terminal and try another
raise # Some other OSError occurred
except: raise
if not ok: raise RuntimeError, "No terminal available!"