Runs each line from the reader until EOF, can be used with Console.In
Syntax
Visual Basic (Declaration) | |
---|
Public Overloads Sub Run( _
ByVal input As TextReader _
) |
Parameters
- input
Example
Library/Library.Test/TestCmdInterpreter.cs
C# | Copy Code |
---|
TextWriter stdout = Console.Out, stderr = Console.Error;
try
{
StringWriter sw = new StringWriter();
Console.SetError(sw);
Console.SetOut(sw);
string result;
CommandInterpreter ci = new CommandInterpreter(new TestCommands());
ci.Prompt = "$(MissingProperty)";
ci.Run(new StringReader("EXIT"));
result = sw.ToString();
Assert.IsTrue(result.StartsWith("Unknown option specified: MissingProperty"));
ci.Prompt = String.Empty;
sw.GetStringBuilder().Length = 0;//clear
ci.Run(new ErrorReader());
result = sw.ToString();
Assert.IsTrue(result.StartsWith(typeof(NotImplementedException).FullName));
}
finally
{
Console.SetOut(stdout);
Console.SetError(stderr);
} |
VB.NET | Copy Code |
---|
Dim stdout As TextWriter = Console.Out, stderr As TextWriter = Console.[Error]
Try
Dim sw As New StringWriter()
Console.SetError(sw)
Console.SetOut(sw)
Dim result As String
Dim ci As New CommandInterpreter(New TestCommands())
ci.Prompt = "$(MissingProperty)"
ci.Run(New StringReader("EXIT"))
result = sw.ToString()
Assert.IsTrue(result.StartsWith("Unknown option specified: MissingProperty"))
ci.Prompt = [String].Empty
sw.GetStringBuilder().Length = 0
'clear
ci.Run(New ErrorReader())
result = sw.ToString()
Assert.IsTrue(result.StartsWith(GetType(NotImplementedException).FullName))
Finally
Console.SetOut(stdout)
Console.SetError(stderr)
End Try |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also