/// <summary> /// Read the output until we see a particular line. /// </summary> /// <param name="_stream"></param> /// <param name="p"></param> private void DumpTillFind(ShellStream stream, string matchText, Action<string> ongo = null) { while (true) { var l = stream.ReadLine(); if (l == null) { Thread.Sleep(100); } else { if (l.Contains(matchText)) { return; } else { if (ongo != null) { ongo(l); } } } } }
public SSHConnection(string host, string username) { this._host = host; this._username = username; _ssh = new SshClient(_host, _username, Passwords.FetchPassword(_host, _username)); _ssh.Connect(); _stream = _ssh.CreateShellStream("commands", 240, 200, 132, 80, 240 * 200); // Next job, wait until we get a command prompt _stream.WriteLine("# this is a test"); DumpTillFind(_stream, "# this is a test"); _prompt = _stream.ReadLine(); }
//terminalden gelen cevabi okumak icin tanimlamlanan cevapoku fonksiyonu.. private void cevapoku(ShellStream stream) { try { while (stream.DataAvailable) { okunan = stream.ReadLine(); } okunan = Regex.Replace(okunan, @"\r", ""); int bas = okunan.IndexOf("<") + "<".Length; int uzunluk = okunan.IndexOf(">") - bas; pinler = okunan.Substring(bas, uzunluk); //pinoku = pinler.select(c => c.ToString()).ToArray(); } catch { tl.LogMessage("hata", "arduino okuma hatasi!!, kapat ac düzelir :) "); } }