Im trying to connect to a unix terminal via plink.exe. The goal is so that I can read the text back into a string.
My dilema is that the bank I work for uses an old as400 type system that we normally access through putty. I'm trying to develop an automation suite that will interface with the system and run jobs and analyse the outputs etc.
So I figured I'd use plink through C#. If I run the code via Command prompt I get (roughly) the text I need back. However im suffering a problem in my C# code in that it just hangs and I never get a reponse.
What I want is like this:
Connect to server Input command Read back screen //More Commands etc
Here is my code so far:
class Program
{
static void Main(string[] args)
{
ProcessStartInfo psi = new ProcessStartInfo(@"C:\Windows\System32\cmd");
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
psi.UseShellExecute = false;
psi.CreateNoWindow = false;
Process process = Process.Start(psi);
string cmdForTunnel = @"c:\putty\plink -ssh jonkers@bankhq -pw automationhero";
process.StandardInput.WriteLine(cmdForTunnel);
// process.WaitForExit();
Thread.Sleep(30000);
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
//DoBusinessLogic();
process.StandardInput.WriteLine("logout");
Thread.Sleep(10000);
if (process.HasExited)
{
process.Close();
process.Dispose();
}
}
}
Im not really sure where the issues lie because as I say ive tested in using plink through command line, but with my solution above it just hangs. Ive tried using other peoples solutions on stackoverflow but none of them seem to work for me as I keep getting this hang. And tips would be much appreciated.
EDIT
I've now decided to use the Renci Sharp SSH library and have build my own framework around this. It works much better.