Code Monkey home page Code Monkey logo

expect's Introduction

Go Report Card

Expect.lua for Windows

  • 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(TEXT) sends TEXT to the terminal as keyboard events.
      • send(TEXT,MS) waits MS [m-seconds] per 1-character (for plink.exe)
    • sendln() is same as send() but append CR.
    • PID=spawn(NAME,ARG1,ARG2,...) starts applications and
      • On success, PID is process-id(integer).
      • On failure, PID is nil.
    • echo() controls echoback
      • echo(true): echo on
      • echo(false): echo off
      • echo("..."): print a string
    • arg[] contains commandline arguments (arg[0] is scriptname)
    • kill(PROCESS-ID) kills the process. (v0.4.0~)
    • spawnctx(NAME,ARG1,ARG2,...) is similar with spawn() but the process started by spawnctx is killed automatically when Ctrl-C is pressed. (v0.5.0~)

Install

Download the binary package from Releases and extract the executable.

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

a690700752 avatar hymkor avatar

Watchers

 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.