def connect(self, cmd, timeout=30):
"""
Returns:
pexpect.spwan object: on success.
False: on Failure
Args:
cmd (string): command to spawn.
timeout (int): default 30 seconds.
Examples:
EX1::
expect = ExpectShell()
expect.connect('telnet shark 2305', timeout=60)
Ex2::
expect = ExpectShell()
expect.connect('gdb a.out')
"""
if not cmd:
return False
if self.shell is None:
try:
log.command("%s" % cmd)
self.shell = pexpect.spawn(cmd, timeout=timeout,
echo=False)
return self.shell
except pexpect.ExceptionPexpect:
log.error("Failed to spwan %s " % cmd)
return False
评论列表
文章目录