[英]pexpect's interact() reported “Inappropriate ioctl for device” when running on a VM with PowerCLI
I have a simple script ( child.py
) as below: 我有一个简单的脚本( child.py
)如下:
#!/usr/bin/env python
import pexpect
def ency():
child = pexpect.spawn("cryptsetup luksChangeKey /mnt/ency")
child.expect('Enter passphrase to be changed:')
child.sendline('password-old')
child.expect('Enter .*: ')
child.sendline('password-new')
child.expect('Verify .*: ')
child.sendline('password-new')
child.interact()
ency()
I invoke this script using a different script ( master.sh
) 我使用不同的脚本( master.sh
)调用此脚本
#!/bin/bash
python child.py
The code run successfully when I run child.py
, but when I envoke child.py
using master.sh
, I get the following error: 该代码成功运行,当我运行child.py
,但是当我envoke child.py
使用master.sh
,我得到以下错误:
Traceback (most recent call last):
File "child.py", line 15, in <module>
ency()
File "child.py", line 13, in ency
child.interact()
File "/usr/lib/python2.7/site-packages/pexpect-4.2.1-py2.7.egg/pexpect/pty_spawn.py", line 740, in interact
mode = tty.tcgetattr(self.STDIN_FILENO)
termios.error: (25, 'Inappropriate ioctl for device')
Note that I am invoking master.sh
using PowerCLI. 请注意,我正在使用PowerCLI调用master.sh
。 I also tried to invoke child.py
directly using PowerCLI's Invoke-vmscript –vm vmname –scripttext “python child.py”
and still get the same behavior. 我还试图直接使用PowerCLI的Invoke-vmscript –vm vmname –scripttext “python child.py”
来调用child.py
,但仍然会得到相同的行为。
Any ideas or suggestions on how to resolve this? 有关如何解决此问题的任何想法或建议?
Thanks 谢谢
Since you are running the pexpect
script on a VM I suppose you don't really need to interact
with it. 由于您在VM上运行pexpect
脚本,我认为您并不需要与它进行interact
。 So just replace 所以只需更换
child.interact()
with 同
child.expect(pexpect.EOF) # also use the `timeout` argument if necessary
to wait for the child to complete. 等孩子完成
According to the doc, interact()
根据文档, interact()
gives control of the child process to the interactive user (the human at the keyboard ). 将子进程的控制权交给交互式用户( 键盘上的人 )。 Keystrokes are sent to the child process, ... 击键被发送到子进程,...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.