pythonapachesubprocessweb2pywinexe

Winexe doesn't exit if launched from apache


I have a web2py application that is running the program "winexe" function through python subprocess.Popen. The problem arises when it is launched winexe: starts correctly but does not exit. Web2py runs on apache using mod_wsgi and with user www-data.

Code:

import os
import pwd
import base64

p = subprocess.Popen(['winexe', '--system', '-U user%password', '//ip_client', '"cmd /C wmic os get osarchitecture"'], stdout = subprocess.PIPE)

output = p.communicate()[0]

print output

if I run the same command from the command line with winexe working properly

winexe -U user%pass //ip_client "cmd /C wmic os get osarchitecture"

OSArchitecture
64 bit

Can you help me? Thanks


Solution

  • For debugging porposes, use:

    from subprocess import Popen, PIPE, STDOUT
    with open('debug.log', 'a') as log:
        log.write('Starting subprocess\n')
        log.flush()
        handle = Popen('winexe --system -U user%password //ip_client "cmd /C wmic os get osarchitecture"', shell=True, stdout=PIPE, stderr=STDOUT, stdin=PIPE)
        log.write('Outputting everything that the subprocess does...\n')
        log.flush()
        while handle.poll() is None:
            log.write('Output: ' + str(handle.stdout.read()) + '\n')
            log.flush()
        log.write('Command ended with code: ' + str(handle.poll()) + '\n')
        log.flush()
        handle.stdout.close()
        handle.stdin.close()