【发布时间】: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