我在Apache2.2上运行一个启用了SSL的django应用程序。当我没有启用SSL时,一切都很好。但是在安全性方面,操作系统如何分离进程可能有一些限制,我完全不知道。在
使用的操作系统:Solaris(不确定是否重要,但可以) Django v1.4、Apache 2.2、Python 2.7
以我的一种观点概括我正在做的事情:
def run_step(request, action): if (action == "action1"): p = subprocess.Popen("command1", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) elif (action == "action2"): password = mylib.getpasswd() ## Method 1: with pexpect command = pexpect.spawn('su root -c \' command2 \'') command.expect('[pP]assword*') command.sendline(password) ## Method 2: with subprocess and a simple command #command = subprocess.Popen('ls > log.file', shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) ## Method 3: with subprocess stdin PIPE #command = subprocess.Popen('command2', shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,stdin=subprocess.PIPE) #command.stdin.write(password) #command.communicate() ## I tried with shell = False, ## with stdin.flush() and communicate(password) too.
“Action1”的命令执行得非常好。但是那些需要互动的人的问题是“行动2”。 我尝试了三种不同的方法:
我不知道现在该怎么办。任何帮助都将不胜感激。在
以下是对我有效的方法:
然后在python中使用一个单独的线程发送一个线程,然后使用一个单独的线程发送一个线程。在
我仍然不明白为什么pexpect模块不能在主线程上工作。我还是很感激你的回答,但我现在还是用这个解决方案。在
相关问题 更多 >
编程相关推荐