【问题标题】:Winexe doesn't exit if launched from apache如果从 apache 启动 Winexe 不会退出
【发布时间】:2014-04-09 10:28:56
【问题描述】:

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

你能帮帮我吗? 谢谢

【问题讨论】:

  • 您没有运行相同的命令,您使用的是--system 一个。其次,在我脑后的某个地方,我很确定您不允许执行系统-来自 wsgi 脚本的命令,但这只是我梦寐以求的东西。你能在每行之间添加打印/日志输出,看看它卡在哪里吗?
  • 就个人而言,我会尝试: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... 我也想过,如果有,我有什么解决方案?
  • 正如我所提到的,尝试with open('debug.log', 'a') as fh: 并在 Web2py 脚本的每一行之间执行fh.write('I came here....')

标签: python apache subprocess web2py winexe


【解决方案1】:

对于调试程序,使用:

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

【讨论】:

  • 与您一起解决方案完美运行在读取输出时出现了一些问题,如上所述,我通过更改解决了这个问题!非常感谢!
猜你喜欢
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 2013-07-17
  • 2018-09-22
  • 2016-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多