expect的使用
expect可以自动化执行需要交互的命令。
安装
yum -y install expect
使用
创建一个文件test.exp
#!/usr/bin/env expect
spawn php go-pear.phar
expect ":"
send "\n"
interact
expect test.exp
python版本
pip install pexpect
#!/usr/bin/env python
# encoding: utf-8
import pexpect
cmd = 'php go-pear.phar'
child = pexpect.spawn(cmd, timeout=None)
child.expect(':')
child.sendline('')
# child.interact()
child.close()