@wiwanek wiwanek released this Mar 13, 2014 · 13 commits to master since this release

Assets 3

Redesigned API, fixed problems with VB.NET

Sample code in C#:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            ISession spawn = Expect.Expect.Spawn(new ProcessSpawnable("cmd.exe"));
            spawn.Expect(">", s => Console.WriteLine("got: " + s));
            spawn.Send("dir c:\\\n");
            spawn.Expect("Program", (s) => Console.WriteLine("found: " + s));
        }
        catch (Exception e)
        {
            Console.Error.WriteLine(e);
        }
        Console.ReadKey();
    }
}

Sample code in VB.NET:

Imports Expect

Module Module1

    Sub Main()
        Dim session As ISession = Expect.Expect.Spawn(New ProcessSpawnable("cmd.exe"))
        Try
            session.Expect(">", Sub(s) Console.WriteLine("Prompt --> " + s))
            session.SetTimeout(1000)
            session.Send("dir c:\" + Environment.NewLine)
            session.Expect("Program Files", Sub(s) Console.WriteLine(s))
            session.Expect(">", Sub() session.Send("ping 8.8.8.8" + Environment.NewLine))
        Catch ex As System.TimeoutException
            Console.WriteLine("Timeout")
        End Try
        session.SetTimeout(5000)
        session.Expect("Lost = 0", Sub() session.Send("ping 8.8.8.8" + Environment.NewLine))
        session.Expect("Lost = 0", Sub(s) Console.WriteLine(s))
        Console.WriteLine("Done")
        Console.ReadKey()
    End Sub

End Module