私はこの質問がたくさん聞かれることを知っていますが、私は始めるための良い方法を見つけることができないようです。
私はsharpsshを使用していますが、コンソールアプリケーション用に作成されています。したがって、winformsアプリケーションを作成しようとすると、希望どおりに実行できません。
私のフォームには次のようなものがあります。出力を表示するテキストボックスユーザーがコマンドを書き込む必要のあるテキストボックス。
readline()で立ち往生しているので、ユーザーがEnterキーを押すまでアプリケーションを一時停止してから、テキストボックスに挿入されたコマンドを送信する必要があります。アプリケーションをwinformアプリケーションに変換する方法がわかりません。
だから問題はこれについてどうやって行くのですか? -アプリケーションの初期化時に開始するプロセスと、出力を受信して入力が必要なときに開始するプロセスを使用する必要がありますか?そして、2番目のプロセスを使用して入力を収集し、テキストボックスで押されたイベント入力キーをリッスンし、他のプロセスを開始して入力を送信し、再び出力を待ちますか?
もしそうなら、それを解決する方法の例がありますか?
これがコードですか?
public Form1()
{
InitializeComponent();
txthost.Text = "XXX";
txtuser.Text = "XXXXX";
txtpass.Text = "XXXXX";
string pattern = "sdf:";
mPattern = pattern;
this.txtInput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(checkforenter);
}
public void button1_Click(object sender, EventArgs e)
{
try
{
mShell = new SshShell(Host, User);
mShell.Password = Pass;
//WRITING USER MESSAGE
txtOutput.AppendText("Connecting...");
mShell.Connect();
txtOutput.AppendText("OK");
//txtOutput.AppendText("Enter a pattern to expect in response [e.g. '#', '$', C:\\\\.*>, etc...]: ");
//Stop for user input
mShell.ExpectPattern = mPattern;
mShell.RemoveTerminalEmulationCharacters = true;
_writer = new TextBoxStreamWriter(txtOutput);
Console.SetOut(_writer);
StringReader reader = new StringReader(txtInput.Text);
while (mShell.ShellOpened)
{
txtOutput.AppendText("\r\n" + "TERMINAL MODE ENGAGED");
txtOutput.AppendText(mShell.Expect( pattern ));
txtInput.Text = Console.ReadLine();
Console.ReadLine();
Console.WriteLine(Environment.NewLine);
txtOutput.AppendText(mShell.Expect(pattern));
MessageBox.Show("innan enter 2");
Console.WriteLine(Environment.NewLine);
txtOutput.AppendText(mShell.Expect(("(continue)")));
MessageBox.Show("efter enter 2");
Console.WriteLine(Environment.NewLine);
//Data from termninal --> Append to text
string output = mShell.Expect(Pattern);
txtOutput.AppendText(output);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}