在C#中打开命令行并发送命令PuTTY或KiTTY [英] Open command line in C# and send commands PuTTY or KiTTY

查看:482
本文介绍了在C#中打开命令行并发送命令PuTTY或KiTTY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从GUI的C#中打开命令行,并发送以下行:

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"

这实际上是打开KiTTY(这是PuTTY的端口),然后将命令 echo 123 (仅作为示例)发送到SSH。

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.

我在C#中找不到任何方法。

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\"");

遵循这些原则可以使您朝正确的方向发展。您将需要在 cmd.StandardInput.WriteLine 中调整调用,以指向 kitty.exe 位置。或者,您可以直接调用 kitty.exe 作为过程,而不是 cmd.exe 并使用 StartInfo.Arguments

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.

还要注意,如果您只需要 Putty的命令行界面,那么您应该研究 Plink ,因为它是 Putty 的命令行版本。

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.

这篇关于在C#中打开命令行并发送命令PuTTY或KiTTY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆