Is it possible to generate log files from a Python file that has been transformed into an executable?

Asked

Viewed 1,474 times

-1

Hello, I create the Python code executable below with the module pyinstaller.

import urllib
import urllib2
import webbrowser
import re
import popular4
import logging
from datetime import datetime
agora = datetime.now()
logging.basicConfig(filename='example2.log', filemode='w', 
level=logging.DEBUG)
while True: 
    tabela    = popular4.Banco()
    if (tabela.PegaEmailDigitado() != tuple()): 
        nome        = tabela.PegaEmailDigitado()[0][0]
        email       = tabela.PegaEmailDigitado()[0][1]
        senha       = tabela.PegaEmailDigitado()[0][2]
        data1       = tabela.PegaEmailDigitado()[0][3]
        matricula   = tabela.PegaEmailDigitado()[0][4]
        rg          = tabela.PegaEmailDigitado()[0][5]
        if (len(email) > 1):
            url = "https://aluno.unb.br/alunoweb/default/sca/solicitarsenha"
            data = urllib.urlencode({'nome': nome, 'matricula': matricula, 
            'identidade': rg,'data_nascimento': data1})
            results = urllib2.urlopen(url, data)
            conteudo_html = str(results.read())
            email_alter = matricula + "@aluno.unb.br"
            if (tabela.is_EmailDuplicado(email)):
                tabela.Inserir(nome, email, senha, data1, matricula, rg, 2)
                tabela.ApagaTabela_transitoria()
                logging.debug("\nHorario do log: %s, nome: %s, email: %s, 
                data: %s, senha: %s, matricula: %s, rg: %s. E-mail já 
                existe, não autenticado.\n"%(agora, nome, email, data1, 
                senha, matricula, rg ))
                continue
        elif (email_alter in conteudo_html ):
            print ("Consegui!")
            tabela.Inserir(nome, email, senha, data1, matricula, rg, 1)
            tabela.ApagaTabela_transitoria()
            logging.debug("\nHorario do log: %s, nome: %s, email: %s, data: 
            %s, senha: %s, matricula: %s, rg: %s, autenticado: Sim \n"%
            (agora, nome, email, data1, senha, matricula, rg ))
        else:
            tabela.Inserir(nome, email, senha, data1, matricula, rg, 0)
            tabela.ApagaTabela_transitoria()
            logging.debug("\nHorario do log: %s, nome: %s, email: %s, data: 
            %s, senha: %s, matricula: %s, rg: %s, autenticado: Não \n"%
            (agora, nome, email, data1, senha, matricula, rg ))
    else:
        logging.debug("\nHorario do log: %s, nome: %s, email: %s, data: %s, 
        senha: %s, matricula: %s, rg: %s, Email Inválido, não autenticado! 
        \n"%(agora, nome, email, data1, senha, matricula, rg ))
        tabela.ApagaTabela_transitoria()
print "Esperando Mudança no Banco..."

When I run the code with the extension . py python nome_do_arquivo.py it generates the log file called example2.log. But when I do the msm file executable and put it to run it does not generate any file. It is possible to do this?

  • Wouldn’t that be a write permission issue? Have you tried running as an administrator?

  • The executable is running -in the background- as root, it does other commands like changes in the Database. However, it does not generate the log file.

  • Has consulted the "When things go wrong", in the pyinstall manual?

1 answer

0


I added the code line below to solve the problem

 #!/usr/bin/env python

Browser other questions tagged

You are not signed in. Login or sign up in order to post.