質問

I want to open the Command line from C# from GUI, and send this line:

kitty.exe abc@192.19.35.80 -load file -l name -pass pswrd -cmd "echo 123"

This is to actually open the KiTTY (which is a port of PuTTY) and send the command echo 123 (which is just an example) to the SSH.

I couldn't find any way doing it in C#.

役に立ちましたか?

解決

System.Diagnostics.Process cmd = new System.Diagnostics.Process();

cmd.StartInfo.FileName = @"C:\windows\system32\cmd.exe";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;

cmd.Start();

cmd.StandardInput.WriteLine("kitty.exe abc@192.19.35.80 -load file -l name -pass pswrd -cmd \"echo 123\"");

Something along those lines should get you in the right direction. You will need to adjust the call in the cmd.StandardInput.WriteLine to point to kitty.exe location. Or you could directly call kitty.exe as the process instead of cmd.exe and use the StartInfo.Arguments.

Also to note that if you are just needing the Command Line Interface of Putty then you should investigate Plink as it is the Command Line Version of Putty.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top