1

我有一个 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

你能帮助我吗?谢谢

4

1 回答 1

0

对于调试 porpose,请使用:

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()
于 2014-04-09T12:11:24.453 回答