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

New Post: Getting blank output using template example

$
0
0
I'm trying to create a very simple script that runs basic commands in a .cshtml page. I can get feedback for standard commands like "ls -l" or "ps -A", but when I try to run a command like "top" or another custom command, I don't get any feedback. It seems like maybe the output type is different for a command that launches a script? The example below is attempting to execute a command that runs a custom script to check if a specific application is running. In my Putty session, I get a response message like "(PID: 19931) is running," but when I run the same command in the code below, I get a blank response (except it does write "Finished" as shown in the code). So I'm not getting any exception errors, just no feedback. I've searched on the forum quite a lot and tried to figure it out myself with no success. Any help is greatly appreciated.
var connectionInfo = new PasswordConnectionInfo(RemoteHost, RemoteUserName, RemotePassWord); 
using (var ssh = new SshClient(connectionInfo))
{
ssh.Connect();
var cmd = ssh.CreateCommand("service tpw status");   //  very long list
                var asynch = cmd.BeginExecute(delegate(IAsyncResult ar)
                {
                    Response.Write("Finished.");
                }, null);

                var reader = new StreamReader(cmd.OutputStream);

                while (!asynch.IsCompleted)
                {
                    var result = reader.ReadToEnd();
                    if (string.IsNullOrEmpty(result)){
                        continue;
                        }
                    Response.Write(result);
                }
                cmd.EndExecute(asynch);

}

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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