开发者

Issues with repeatedly executing .pyc script

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜