Python Winexe没有';如果从apache启动,则无法退出

Python Winexe没有';如果从apache启动,则无法退出,python,apache,subprocess,web2py,winexe,Python,Apache,Subprocess,Web2py,Winexe,我有一个web2py应用程序,它通过python subprocess.Popen运行程序“winexe”函数。 当启动winexe:时会出现问题:正确启动但不退出。Web2py使用mod_wsgi和用户www数据在apache上运行 代码: 如果我在winexe正常工作的情况下从命令行运行相同的命令 winexe -U user%pass //ip_client "cmd /C wmic os get osarchitecture" OSArchitecture 64 bit 你能帮我吗?

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

代码:

如果我在winexe正常工作的情况下从命令行运行相同的命令

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

OSArchitecture
64 bit
你能帮我吗?
感谢您调试porposes,请使用:

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

您运行的不是同一个命令,而是使用
--system
作为一个命令。。其次,在我脑后的某个地方,我很确定你不允许从wsgi脚本执行系统命令,但那只是iv'e梦寐以求的。。你能在每行之间添加打印/日志输出,看看它在哪里卡住了吗?我个人会尝试:
p=subprocess.Popen('winexe--system-U user%password//ip_client“cmd/C wmic os get osarchitecture”,stdout=subprocess.PIPE,shell=True)
对不起,我忘了--system,但结果是一样的。我还尝试了p=subprocess.Popen('winexe--system-U user%password//ip_client“cmd/C wmic os get-osarchitecture”,stdout=subprocess.PIPE,shell=True),结果与WSGI相同。。。我还想,如果是的话,我有什么解决方案?正如我提到的,试着用open('debug.log','a')作为fh:和do
fh.write('I come here…')
在Web2py脚本的每一行之间。有了你的解决方案,在读取输出时出现了一些问题,如上所述,我通过更改解决了!!谢谢!
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()