Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: How to deal with the error stream when using ShellStream

$
0
0
When I use ShellStream to get the output like putty or plink,i have some questions.
First,I can get the stdout correctly by using following codes.
            ShellStream shells = client.CreateShellStream("test", 80, 24, 800, 600, 1024);
            string input = "ping 127.0.0.1 -c 10";
            shells.WriteLine(input);
            Regex regex = new Regex(@"\[.*@.*\][\$|\#]");
            
            string output = String.Empty;
            var match = regex.Match(output);
            while (shells.DataAvailable || !match.Success)
            {
                if (shells.CanRead)
                    output = shells.ReadLine();
                match = regex.Match(output);
                if (!output.StartsWith("Last login") && !(output.EndsWith(input) && i < 4))
                    Console.WriteLine(output);
                Thread.Sleep(200);
            }
and then ,here is the output
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.016 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.019 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.021 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.022 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.020 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.020 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.021 ms

--- 127.0.0.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9000ms
rtt min/avg/max/mdev = 0.016/0.021/0.026/0.005 ms
but when i change the input like this
string input = "cd /home/t";
and ,in putty,the output is like this
-bash: cd : /home/t : No such file or directory
but,using my codes, there is no output.so, my question is how to get the error stream.

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>