Как передать Y
в процесс, запущенный System.Diagnostic.Process
в PowerShell?
function Start-NewPlinkProcess(
[string]$pfile = 'plink.exe',
[string]$arguments = 'somehost -l somelogin -pw somepasswd ping -c 12 someOtherHost > /home/homeie/mePingTestResults.txt'
){
$p = New-Object System.Diagnostics.Process;
$p.StartInfo.UseShellExecute = $false;
$p.StartInfo.RedirectStandardOutput = $true;
$p.StartInfo.RedirectStandardInput = $true;
$p.StartInfo.FileName = $pfile;
$p.StartInfo.Arguments = $arguments
$p.StandardInput.WriteLine("Y") # Pass a Y to stdin ignore that...
$pident = ($p.Start()).Id
Write-Host("pid: $($pident)");
#$p.WaitForExit();
#$p.StandardOutput.ReadToEnd();
return $p
}
Когда я звоню, я все равно получаю:
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)
Я читал в другом месте, что можно попробовать что-то вроде echo y | plink ...
и сделать так, чтобы оно читало это по трубопроводу со стандартного ввода, но я хочу иметь больший контроль над этим, чем это.