0

I have a Desktop Icon(Linux Mint system) that calls a script (conky) but also needs to exit so I don't have a terminal window open all the time. I'm trying to convert this to an onscreen python button.

I can get Python Button to run the script but I can't get it to close the terminal once the script is up and running fine.

This is the normal command: /home/user/.conky_start.sh && exit

Current Python Button Script:

import Tkinter
from Tkinter import *
import subprocess

top = Tkinter.Tk()

def run_conky():
   subprocess.call(['/home/user/.conky_start.sh', '&&', 'exit'], shell=True)

B = Tkinter.Button(top, text ="Conky", command = run_conky)

B.pack()
top.mainloop()
Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
DragonDon
  • 49
  • 9
  • 2
    [Don't use a list argument together with shell=True.](http://bugs.python.org/issue21347) – jfs Jan 18 '15 at 13:30
  • Do you want to exit the Python script after `.conky_start.sh` is started? – jfs Jan 18 '15 at 13:31
  • possible duplicate of [Understanding python subprocess.check\_output's first argument and shell=True](http://stackoverflow.com/questions/21029154/understanding-python-subprocess-check-outputs-first-argument-and-shell-true) – Joe Jan 18 '15 at 13:38

2 Answers2

0

You should use:

subprocess.call('/home/user/.conky_start.sh && exit', shell=True)

When shell=True the first argument to call must be a string which represent the command line. If you pass a list the first element is used as command line and the other arguments are passed to the underlying shell as options.

In other words, the && exit in your code was never executed because it was passed as options to the shell (which probably simply ignored the unrecognized options).

See this question for more information about arguments to subprocess functions.

Community
  • 1
  • 1
Bakuriu
  • 98,325
  • 22
  • 197
  • 231
  • Thanks for the suggestion. Actually, that was the first thing I tried. Sadly, this does not make a difference to the exit issue. – DragonDon Jan 18 '15 at 15:16
0

To exit the Python script after the attempt to start the shell script:

#!/usr/bin/env python
import subprocess
import Tkinter

root = Tkinter.Tk()

def start_conky():
    try:
        subprocess.Popen(['/home/user/.conky_start.sh']) # don't wait
    finally:
        root.destroy() # exit the GUI

Tkinter.Button(root, text="Conky", command=start_conky).pack()
root.mainloop()
jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • Awesome, this works and gets me one step further! Hmm, while the script did exit, it started outputting more info. One of the other scripts that gets called looks for a running media player to display song title/artist. It kinda complains that it can't find anything constantly. Will have to look into that another day. Wish I could upvote but aparently I need 9 more reputation points :/ Consider this an upvote :) – DragonDon Jan 18 '15 at 15:19