Giter Club home page Giter Club logo

expect's Introduction

Go Report Card

Expect for Windows Powered by GopherLua

  • A tool like expect on Linux.
  • Scripts are to be written with Lua (GopherLua)
  • Some built-in functions exists:
    • rc=expect(A,B,C...) accesses CONOUT$ directly and watches the cursor-line (0.1 seconds interval)
      • When A was found in cursor-line, rc=0
      • When B was found in cursor-line, rc=1
      • When C was found in cursor-line, rc=2
      • :
      • When error occured, rc=-1
      • When timeout occurs, rc=-2 (set variable like timeout=(SECONDS),default 1 hour)
    • send() causes keyboard events against CONIN$.
      • send(S,MS) waits MS [m-seconds] per 1-character (for plink.exe)
    • sendln() is same as send() but append CR.
    • spawn() starts applications and returns true on success or false on failure.
    • echo() controls echoback
      • echo(true): echo on
      • echo(false): echo off
      • echo("..."): print a string
    • arg[] contains commandline arguments (arg[0] is scriptname)

Sample

sample.lua:

echo(true)
if spawn([[c:\Program Files\Git\usr\bin\ssh.exe]],"[email protected]") then
    expect("password:")
    echo(false)
    send("PASSWORD\r")
    expect("~]$")
    echo(true)
    send("exit\r")
end

On the command prompt:

$ expect.exe sample.lua
[email protected]'s password:
Last login: Thu Jun 15 13:21:57 2017 from XXXXXXXXXXXX.XXXX.XX.XXX.XXX.XXXXXXX.XX.XX
FreeBSD 9.1-RELEASE-p24 (XXXXXXXX) #0: Thu Feb  5 10:03:29 JST 2015

Welcome to FreeBSD!

[foo@XXXXXXX ~]$ exit
logout
Connection to example.com closed.

The script embeded in the batchfile:

@expect.exe "%~f0"
@exit /b

-- Lines starting with '@' are replaced to '--@' by expect.exe
-- to embed the script into the batchfile.

echo(true)
if spawn([[c:\Program Files\Git\usr\bin\ssh.exe]],"[email protected]") then
    expect("password:")
    echo(false)
    send("PASSWORD\r")
    expect("~]$")
    echo(true)
    send("exit\r")
end

expect's People

Contributors

hymkor avatar a690700752 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.