Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2206,12 +2206,54 @@ internal int StartSSHProcess(
var context = Runspaces.LocalPipeline.GetExecutionContextFromTLS();
if (context != null)
{
var cmdInfo = context.CommandDiscovery.LookupCommandInfo(sshCommand, CommandOrigin.Internal) as ApplicationInfo;
var cmdInfo = CommandDiscovery.LookupCommandInfo(
sshCommand,
CommandTypes.Application,
SearchResolutionOptions.None,
CommandOrigin.Internal,
context) as ApplicationInfo;

if (cmdInfo != null)
{
filePath = cmdInfo.Path;
}
}
else
{
// A Runspace may not be present in the TLS in SDK hosted apps
// or if running in another thread without a Runspace. While
// 'ProcessStartInfo' can lookup the full path in PATH, it searches
// the process' working directory first. 'LookupCommandInfo' does
// not search the process' working directory and we want to keep that
// behavior. We also get the parent dir of the full path to set as the
// new WorkingDirectory. So, we do a manual lookup here only in PATH.
string[] entries = Environment.GetEnvironmentVariable("PATH")?.Split(
Path.PathSeparator,
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? [];
foreach (var path in entries)
{
if (!Path.IsPathFullyQualified(path))
{
continue;
}

var sshCommandPath = Path.Combine(path, sshCommand);
if (File.Exists(sshCommandPath))
{
filePath = sshCommandPath;
break;
}
}
}

if (string.IsNullOrEmpty(filePath))
{
throw new CommandNotFoundException(
sshCommand,
null,
"CommandNotFoundException",
DiscoveryExceptions.CommandNotFoundException);
}

// Create a local ssh process (client) that conects to a remote sshd process (server) using a 'powershell' subsystem.
//
Expand Down
Loading