0

I am trying to open hypertrm.exe using myProcess.StartInfo.FileName = @"hypertrm.exe"; in c#.Now as per my requirement i need to login into the machine by entering username and password.For login to the machine i am writing following commands ..

Process hyperProcess = new Process();
hyperProcess.StartInfo.FileName = @"hypertrm.exe";
hyperProcess.EnableRaisingEvents = true;
hyperProcess.Start();

if (hyperProcess.Responding)
{
    string username = "username";
    System.Windows.Forms.SendKeys.SendWait(username + "{ENTER}");

    Application.DoEvents();
    Thread.Sleep(5000);
    //Similarly Entered Password
}

Now as soon as Username,password entered correctly text data will be dispalyed into the hyperterminal window.Now how can i write that data into text file programmatically using c#.

Here is my updated code by which i want to open .ht file which i created as connection file and now i want to open with the help of hyperterminal and execute some commands in the hyperterminal.

            var fileToOpen = @"D:\HyperTerminal\test.ht";
            var myProcess = new Process();
            myProcess.StartInfo = new ProcessStartInfo()
            {
                UseShellExecute = true,
                FileName = fileToOpen
            };

            myProcess.Start();               

            if (myProcess.Responding)
            {
                string username = "";

                System.Windows.Forms.SendKeys.SendWait(username + "{ENTER}");

                Application.DoEvents();

                Thread.Sleep(5000);

                string password = "";

                System.Windows.Forms.SendKeys.SendWait(password + "{ENTER}");

                Application.DoEvents();

                Thread.Sleep(5000);

                string Command = "";

                System.Windows.Forms.SendKeys.SendWait(Command + "{ENTER}");

                Application.DoEvents();

                Thread.Sleep(5000);


                using (var writer = new StreamWriter(@"E:/Hyper/data.txt"))                    
                {
                    writer.Write(myProcess.StandardOutput.ReadToEnd());
                }

                myProcess.Close();

            }

        }           
        catch
        {
        }

Now i want to know that is my approach correct to get the data from the hyper terminal.

Please help me ..Thanks in advance..

Ram
  • 545
  • 6
  • 16
  • 28
  • Look at using the SerialPort class directly in C#, rather than interacting with HyperTerm via console app. Google will help. http://www.codeproject.com/Questions/695712/reading-data-from-hyperterminal-serial-port-csharp – John Arlen Apr 03 '14 at 14:00
  • @JohnArlen Sir i tried to do that only and i was partial success also but what is the problem that i am not getting buffer data of the machine ... – Ram Apr 04 '14 at 04:41

1 Answers1

0

You can redirect the output of the process. Look up RedirectStandardOutput.

var process = new Process
    {
        StartInfo = {
            FileName = @"ping.exe", 
            UseShellExecute = false, 
            RedirectStandardOutput = true
        }
    };

process.Start();

using ( var writer = new StreamWriter( @"output.txt" ) )
{
    writer.Write( process.StandardOutput.ReadToEnd() );
}
John Arlen
  • 6,539
  • 2
  • 33
  • 42
  • Sir i created a Hyper terminal Connection name and now i want to open that through process.Start() but as soon as this code executes random alert box comes as error "could not read session file" and title of the error box is "Hyperterminal".why is this coming sir and how to resolve it? – Ram Apr 03 '14 at 08:54