sanctus Posted August 30, 2013 Report Posted August 30, 2013 Hi all, I wrote this following little code to run at startup. When I run it from the terminal it all works fine (but there is no point of the program (or better only 2/3, since I use it to open 3 programs among which a terminal)), but when I run it as executable (i.e double click and select run) the first time it opens only a terminal and only the second time it opens rhythmbox firefox and another terminal window. As to the reason for this script I just started teaching myself python and though a good way to see how scripts work is actually to write one from scratch... (I know that most likely this could be done in an easier way just in bash, but easy is not the scope:-) ) Also, obviously it never greets me when run by double click (no screen to print 'hello' to) #! /usr/bin/env python print 'hello' import os,subprocess from subprocess import Popen, PIPE os.system('gnome-terminal') os.system('/usr/bin/rhythmbox &') #-b shows the whole output from top not only that fitting to terminal window #-n1 no refreshing of top just run once proc = subprocess.Popen(["top -b -u sandros -n1 "], shell=True, stdout=PIPE) topout=[""] for line in proc.stdout: # print line topout.append(line) i=0 for item in topout: if item.find("firefox") != -1: print "firefox is running" i=1 break# stop loop if firefox found # else: if i==0: os.system('firefox') Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.