我需要在代码中远程执行一些PowerShell命令。为此,我使用.net ssh客户端。除了管道命令解释之外,一切都有效。下面的代码会返回一个错误:
DEBUG:'Stop-Process'未被识别为内部或外部命令、可操作程序或批处理文件。
using System.IO;
using Or1WinAppDriverTests.Properties;
using Renci.SshNet;
using Xunit;
using Xunit.Abstractions;
namespace Or1WinAppDriverTests.aidaTests {
public class AidaMachineSshAccessTests
{
public AidaMachineSshAccessTests(ITestOutputHelper output)
{
this._output = output;
}
private readonly ITestOutputHelper _output;
[Fact]
public void SshTest3()
{
var host = Resources.HOST;
var username = Resources.USERNAME;
var password = Resources.PASSWORD;
using (var client = new SshClient(host, username, password))
{
#region Example SshCommand CreateCommand Execute ExtendedOutputStream
client.Connect();
var cmd2 = client.CreateCommand(
$"powershell.exe -executionPolicy bypass ;" +
$"Get-Process notepad | Stop-Process ;" +
$"exit ;");
var result = cmd2.Execute();
_output.WriteLine(result);
var reader = new StreamReader(cmd2.ExtendedOutputStream);
_output.WriteLine("DEBUG:");
_output.WriteLine(reader.ReadToEnd());
client.Disconnect();
#endregion Example SshCommand CreateCommand Execute ExtendedOutputStream
}
}
}
}
CMD
毫无意义。 - Panagiotis Kanavos