本文整理汇总了C#中Shell.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Shell.Run方法的具体用法?C# Shell.Run怎么用?C# Shell.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shell
的用法示例。
在下文中一共展示了Shell.Run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestHead
public void TestHead()
{
var shell = new Shell(o => o.StartInfo(si => si.RedirectStandardError = false));
var command = shell.Run("SampleCommand", "head", "10") < Enumerable.Range(0, 100).Select(i => i.ToString());
command.Task.Result.StandardOutput.Trim().ShouldEqual(string.Join(Environment.NewLine, Enumerable.Range(0, 10)));
}
示例2: TestCloseStandardOutput
public void TestCloseStandardOutput()
{
var shell = new Shell(o => o.StartInfo(si => si.RedirectStandardError = false));
var command = shell.Run("SampleCommand", "grep", "a") < Enumerable.Repeat(new string('a', 1000), 1000);
command.StandardOutput.BaseStream.ReadByte();
command.StandardOutput.BaseStream.Dispose();
UnitTestHelpers.AssertThrows<ObjectDisposedException>(() => command.StandardOutput.BaseStream.ReadByte());
UnitTestHelpers.AssertThrows<ObjectDisposedException>(() => command.StandardOutput.ReadToEnd());
var command2 = shell.Run("SampleCommand", "grep", "a") < Enumerable.Repeat(new string('a', 1000), 1000);
command2.Wait();
command2.StandardOutput.Dispose();
UnitTestHelpers.AssertThrows<ObjectDisposedException>(() => command2.StandardOutput.Read());
}
示例3: TestExitCode
public void TestExitCode()
{
if (!Command.Run("SampleCommand", "exit", 0).Result.Success)
{
Assert.Fail("Should have worked");
}
if (Command.Run("SampleCommand", "exit", 1).Result.Success)
{
Assert.Fail("Should have failed");
}
var shell = new Shell(o => o.ThrowOnError());
var ex = UnitTestHelpers.AssertThrows<AggregateException>(() => shell.Run("SampleCommand", "exit", -1).Task.Wait());
ex.InnerExceptions.Select(e => e.GetType()).SequenceEqual(new[] { typeof(ErrorExitCodeException) })
.ShouldEqual(true);
shell.Run("SampleCommand", "exit", 0).Task.Wait();
}