pexpect's interact() reported "Inappropriate ioctl for device" when running on a VM with PowerCLI

1.7k views Asked by At

I have a simple script (child.py) as below:

#!/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)

#!/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:

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. 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.

Any ideas or suggestions on how to resolve this?

Thanks

1

There are 1 answers

0
pynexj On BEST ANSWER

Since you are running the pexpect script on a VM I suppose you don't really need to interact with it. 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()

gives control of the child process to the interactive user (the human at the keyboard). Keystrokes are sent to the child process, ...