如果从apache启动,Winexe不会退出

时间:2014-04-09 10:28:57

标签: python apache subprocess web2py winexe

我有一个web2py应用程序,它通过python subprocess.Popen运行程序“winexe”。 启动winexe时出现问题:正确启动但不退出。 Web2py使用mod_wsgi和用户www-data在apache上运行。

代码:

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

如果我从命令行运行相同的命令,winexe正常工作

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

OSArchitecture
64 bit
你能帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:0)

对于调试目的,请使用:

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()