How to spawn command - wiwanek/Expect.NET GitHub Wiki
Expect.Spawn(ISpawnable)
function creates a Session
object with implementation of ISpawnable
interface. Spawned sessions can be automated using Session
methods such as Session.Expect()
and Session.Send()
.
To automate console application should be used CommandSpawnable
class. The CommandSpawnable
wraps System.Diagnostics.Process
class to run and control local application.
CommandSpawnable
has three constructor variants:
ProcessSpawnable(string command)
- accepts command to execute as string. Example:
Session s = Expect.Spawn(new ProcessSpawnable("cmd.exe"));
ProcessSpawnable(string command, string arguments)
- accepts command to execute as a string and command-line arguments as a string. Example:
Session s = Expect.Spawn(new ProcessSpawnable("cmd.exe", "\?"));
ProcessSpawnable(Process process)
- accepts Process object with configured filename. Process should not be started prior passing to constructor - it will be started during creation of session. Example:
string filename = "testFileName";
string args = "arg1 arg2";
Process p = new Process();
p.StartInfo.FileName = filename; // It's mandatory
p.StartInfo.Arguments = args; // It's optional
ProcessSpawnable proc = new ProcessSpawnable(p);
Session s = Expect.Spawn(proc);