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

New Post: Dealing with "prompts"

$
0
0
Well I thought id made progress, but apparently using the ShellStream fudges up creating a command and trying to read the result. If I create a stream and then use: result = resultStream.ReadToEnd(); it just hangs and doesnt run Asynch like its supposed to. Stupid machine kicks box

Here is how i implemented sending a command and looking for a return:
    public static void SendShellCommand(string command, List<string> passCriteria, TimeSpan timeout)
    {
        stream.Flush();
        var reader = new StreamReader(stream);
        var writer = new StreamWriter(stream);
        int numOfPassCriteriaMet = 0;
        int numOfPassCriteriaExpected = passCriteria.Count;
        bool passCriteriaMet = false;
        string line = "";
        String[] output;
        Stopwatch myWatch = new Stopwatch();

        try
        {
            writer.AutoFlush = true;
            stream.Flush();
            myWatch.Start();
            writer.WriteLine(command);
            line = "";

            while (myWatch.Elapsed < timeout & passCriteriaMet == false)
            {

                line = line + reader.ReadToEnd();
                output = line.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                resultArray = output;

                foreach (string value in passCriteria)
                {
                    foreach (string outputValue in output)
                    {
                        if (outputValue.Contains(value, StringComparison.CurrentCultureIgnoreCase))
                        {
                            numOfPassCriteriaMet++;
                        }
                        if (numOfPassCriteriaMet == numOfPassCriteriaExpected)
                        {
                            passCriteriaMet = true;
                            break;
                        }
                    }
                    if (passCriteriaMet)
                    {
                        break;
                    }
                }
                Thread.Sleep(100);
            }

            myWatch.Stop();
            myWatch.Reset();

            if (passCriteriaMet)
            {
                WebDriver.myLogger.LogPass("Executed VMS command: " + command);
            }
            else
            {
                WebDriver.myLogger.LogFail("One or more steps failed executing the VMS command: " + command);

                    foreach (string result in resultArray)
                    {
                        string comment = Regex.Replace(result, @"[^\u0000-\u007F]", string.Empty);
                        WebDriver.myLogger.LogComment(comment.Trim());
                    }
            }
        }
        catch(Exception ex)
        {
            myWatch.Stop();
            myWatch.Reset();
            WebDriver.myLogger.LogFail("Error executing VMS command: " + command + " | " + ex.Message);
        }
        WebDriver.TestLog().LogStep(WebDriver.TestLog().GetTestResult(), "Execute command");

    }

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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