简体   繁体   English

当在具有PowerCLI的VM上运行时,pexpect的interact()报告“不适当的设备ioctl”

[英]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.

相关问题 Pexpect和PyCharm - 适用于设备的ioctl - Pexpect and PyCharm - Inappropriate ioctl for device 在Python中运行ioctl会返回ENOTTY-设备不适合的ioctl - Running ioctl in Python returns ENOTTY - inappropriate ioctl for device 崇高的tset:标准错误:设备的ioctl不适当 - Sublime tset: standard error: Inappropriate ioctl for device IOError:[Errno 25] 设备的 ioctl 不合适 - IOError: [Errno 25] Inappropriate ioctl for device opencv无法阻止流:设备的ioctl不合适 - opencv Unable to stop the stream: Inappropriate ioctl for device OpenCV3错误:“无法停止流:设备的不适当的ioctl” - OpenCV3 error: “Unable to stop the stream: Inappropriate ioctl for device” 如何抑制“stty:'标准输入':设备的 ioctl 不合适”错误 - How to supress the “stty: 'standard input': Inappropriate ioctl for device” error 詹金斯的pipenv shell返回问题termios.error:(25,&#39;不合适的设备ioctl&#39;) - pipenv shell in Jenkins return the issue termios.error: (25, 'Inappropriate ioctl for device') “GetPassWarning:无法控制终端上的回声”是什么意思? “设备的 ioctl 不合适”? - What does "GetPassWarning: Can not control echo on the terminal" mean? "Inappropriate ioctl for device"? 使用Ubuntu和pty不合适的ioctl - Inappropriate ioctl using Ubuntu and pty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM