I am trying to make an script that will every second read string from a file, and execute it.
executer.pyc:
import os, time
f = open("/root/codename/execute","a")
f.write("")
f.close()
cmd=open('/root/codename/execute', 'r').read()
if not cmd==""开发者_StackOverflow中文版:
os.system(cmd)
os.system("rm /root/codename/execute")
time.sleep(1)
os.system("python executer.pyc")
Problem is, that it constantly f's up whole ps -aux and other similiar commands. How can i make, that it will kill itself and then launch itself again? My idea, is a parent script that will launch executer.pyc everytime that script closes itself. But how can i make it, that it will not have effect like executer.pyc? I know this whole system how it works is kinda bad, but i just need it this way (reading from file "execute"). Please help!
Thanks in advance!
instead of
os.system("python executer.pyc")
you can use execfile()
It will be much easier to let this script run continuously. Look at How to use a timer to run forever? This will show you how you can repeatedly execute the same command.
精彩评论