我正在处理一个Virtuozzo服务器,我想通过为'vzctl enter‘创建一个子进程,在Python中自动登录到每个容器并发出一些命令。
这是我现在正在做的代码片段-
#!/usr/bin/python
import subprocess
print 'Start'
proc = subprocess.Popen(['vzctl enter 123'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
shell=True)
print proc.communicate('whoami')[0]
print 'Finished'但我每次看到的输出是-
Unable to get term attr: Invalid argument
Unable to restore term attr: Invalid argument我真的认为这是一个BASH错误,有人能给我一个建议吗?
发布于 2010-07-10 22:01:03
看起来vzctl期望stdin/stdout是一个终端。您可以通过实验(在bash中)找出其中的原因:
$ echo whoami | vzctl enter 123 # stdin is not a tty
$ vzctl enter 123 | cat # stdout is not a tty
whoami
<ctrl-d>您可以使用标准库中的pty模块来创建伪类型,但该模块的级别非常低。
有一个名为pexpect的第三方模块可能符合这一要求。
https://stackoverflow.com/questions/3198617
复制相似问题