2016-12-29 10 views
1

でVM上で動作している場合は、以下のように私は簡単なスクリプト(child.py)を持っている「デバイスの不適切なioctlのを」報告:私は別のスクリプト(master.sh)を使用して、このスクリプトを呼び出すpexpectの相互作用()PowerCLIの

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

#!/bin/bash 
python child.py 

私はchild.pyを実行するが、私はmaster.shを使用してchild.pyをenvokeとき、私は次のエラーを取得する際に正常に実行コード:

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') 

PowerCLIを使用してmaster.shを呼び出すことに注意してください。私もchild.pyをPowerCLIのInvoke-vmscript –vm vmname –scripttext “python child.py”を使って直接呼び出そうとしましたが、それでも同じ動作をします。

これを解決する方法に関するご意見やご提案はありますか?

おかげ

+0

は、シェルスクリプトをmaster.py' 'ですか?なぜ 'python child.py'ですか? – pynexj

+0

masterはpythonファイル、childはbashスクリプトです。私はこれを反映するために私の質問を編集しました。これを指摘してくれてありがとう。 – Taleeb

+1

* masterはpythonファイルですが、childはbashスクリプトです*、あなたは@Taleebの周りに他の方法ではないと確信していますか?また、 'master.py'をどう呼びますか? – Gabriel

答えて

0

あなたは私はあなたが本当にそれでinteractする必要はありませんと仮定VM上pexpectスクリプトを実行しているので。だから完成するを待つこと

child.expect(pexpect.EOF) # also use the `timeout` argument if necessary 

child.interact() 

を交換してください。


ドキュメントによると、interact()

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

+0

これは私にとって完璧に機能します。ありがとう – Taleeb