io - Capturing Plink output in C# -
I am trying to use the Planck to access information on the machine. I follow this tutorial:
So far I will just open the plaque using my program, and I will add the login information and at least in this time the plaque can be open to me In my program I have this tutorial based on:
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); Thread.Sleep (3000); String cmdForTunnel = "plink"; Process.StandardInput.WriteLine (cmdForTunnel); Process.WaitForExit (); Thread.Sleep (10000); // DoBusinessLogic (); Process.StandardInput.WriteLine ("logout"); Thread.Sleep (10000); If (process.HasExited) {process.Close (); Process.Dispose (); } but nothing has been shown, which bothers me to assume to display help information about how to use the command plink program (I will replace the command with some more useful later), but the command prompt remains empty I also used the clerk with ipconfig , whatever Not displayed.
I know how to open CMD and type in plink to access it. I want to repeat this verb in my program.
There are several flaws in your code:
- You get an output Are redirecting, and you are not reading / processing / printing it (this is why "nothing looks" )
- clerk " Typing "
clerktocmd.exeis crazy. You can runplinkdirectly, withcmd.execompletely (and even if you usecmd.exe, You needPlink.exeon the command-line:/ c path \ plink.exe). Otherwise, it will not be the reason for to stop immediately by running it directly. - Calling
WaitForExit ()returns your code once an output buffer without reading the redirect output. For the Comments section see Alternatively, use (this is the same asWaitForExit, but it also reads the output). What it really recommends for MSDN in previous links. -
If you are going to execute only one command, using the plink, "typing" command line on the command line in your (redirect) input:
plink.exe -ssh user @ host command
See also the answer
Comments
Post a Comment