我想運行一個Python程序來查看屏幕程序是否正在運行。如果是,那麼程序不應該運行其餘的代碼。這是我已經和它不工作:如何判斷屏幕是否在運行?
#!/usr/bin/python
import os
var1 = os.system ('screen -r > /root/screenlog/screen.log')
fd = open("/root/screenlog/screen.log")
content = fd.readline()
while content:
if content == "There is no screen to be resumed.":
os.system ('/etc/init.d/tunnel.sh')
print "The tunnel is now active."
else:
print "The tunnel is running."
fd.close()
我知道有可能在這裏幾件事情,並不需要而且相當多的我失蹤。我將在cron中運行這個程序。
它將它寫入文件。當我嘗試重定向它時,它不會向該文件寫入任何信息。 – spxxn 2010-04-30 16:22:51