Riattiva programma

Il linguaggio di nuova generazione, opinioni, dubbi e aiuti.

Moderator: checkm

Riattiva programma

Postby eXiD on Wed Jul 18, 2007 6:22 am

Versione 1, stabile.

Code: Select all
import os
import time

nome = raw_input("Nome > ")
delay = raw_input("Tempo > ")

a = os.popen("ps aux |grep "+nome+"").read()
a = a.split("\n")
a = a[0]
a = a.split(" ")

while 1:
    if a[-1] == nome:
        print "Processo attivo"
   
    else:
        print "Processo non attivo, attivazione in corso..."
        os.system (nome)

    time.sleep(int(delay))



Versione 2, alpha, se volete svilupparla voi, io mi sono rotto le palle :)

Code: Select all
import os
import time

auto = '0'
flag = 0

while auto != 's' and auto!= 'n':
    auto = raw_input(" Attivazione automatica? [s,n] > ")
   
tempo = raw_input(" Inserire il tempo di controllo > ")

while flag != 1:
    nome = raw_input(" Inserire nome processo > ")
    a = os.popen("ps aux | grep "+nome+"").read()
    a = a.split("\n")
    a = a[0]
    a = a.split(" ")

    for obj in a:
        if obj == 'grep':
            flag = 0
            break
        else:
            flag = 1
   
    if flag == 0:
        print " Processo non esistente, re-inserisci..."
        time.sleep(1)

while 1:
    time.sleep(int(tempo))
   
    if a[-1] == nome:
        print "Processo attivo"
   
    else:
        print "Processo non attivo"

        if auto == 's':
            print " Attivazione in corso..."
            os.system (nome)
        else:       
            print " Premere un tasto per attivare !"
            raw_input("")
            os.system (nome)



un saluto
User avatar
eXiD
Newbies
 
Posts: 81
Joined: Fri Apr 13, 2007 4:54 pm

Riattiva programma

Sponsor

Sponsor


Return to Python

Who is online

Users browsing this forum: No registered users and 1 guest