我在 plink.exe 上使用 Process.Start 在 Linux 机器上运行远程调用。这很好用,除非在 NUnit 的上下文中运行(我已经尝试过 TestDriven.NET 和 ReSharper 的单元测试运行器)。
在 NUnit 测试中,进程似乎立即关闭,实际上并没有做任何事情,就像有什么东西迫使它关闭一样。
这是代码,请注意,在控制台应用程序的上下文中,它可以完美运行。
var processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = @"D:\Tools\plink\plink.exe";
processStartInfo.Arguments = "-ssh #some parameters here#;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
var process = new Process();
process.StartInfo = processStartInfo;
process.Start();
var output = process.StandardOutput.ReadToEnd();