Solved

C# Dotnet 4.5, need help with using StartInfo.RedirectStandardOuput to display to webscreen

Posted on 2013-12-10
1
309 Views
Last Modified: 2014-01-02
I need a hand figuring out (more like I hit a wall) how to use StartInfo.RedirectStandaredOutput to display a message on my web screen when a user hits the submit button. Basically what I have is a c# webpage that has the option to bring my system into Maint mode or bring it out of Maint mode. you select the option and hit submit which then calls a Powershell script behind the scenes that does all the work and writes out a log file in the process. The final piece that I am working on now is just to display a specific message on screen so if a user selects to begin maint mode it will display a message on screen  saying "system down for maintenance" or "System Is Up" after they select the option to end maint mode and hit submit.
I am using a simple default.aspx page with a drop down list and submit button. In my default.aspx.cs I have the following code that I am using:

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)

        {
            string[] args = Environment.GetCommandLineArgs();
            Process proc = new Process();
            proc.StartInfo.FileName = null;
            proc.StartInfo.WorkingDirectory = @"c:\scripts";
     

            if (this.DropDownList1.SelectedValue == "PRO Sybase Restart Begin")
            {
               
                proc.StartInfo.FileName = @"Powershell.exe";
                proc.StartInfo.Arguments = @"& 'C:\Scripts\StopSVCFinal.ps1'";
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow = true;
               
               
            }
            else if (this.DropDownList1.SelectedValue == "PRO Sybase Restart Complete")
            {
                proc.StartInfo.FileName = @"Powershell.exe";
                proc.StartInfo.Arguments = @"& 'C:\Scripts\StartSVCFinal.ps1'";
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow = true;
            }

 if (proc.StartInfo.FileName != null)
            {
                proc.Start();
       
             
            }

With the code I am using is it possible to pass something like "system is down for maintenance" into a string and then write that out to the screen. OR if it would be easier I would be fine with just doing something simpler like allowing the user to select the maint begin option in the drop down and display an Image file (that says sytem down or whatever)  to the web interface when they click submit. That would work provided it stays there until they click submit to bring the system out of maint mode. I have added my default.aspx.cs and default.aspx to help make a bit more sense of what I am doing..

Does that explanation clear as mud? If there is a better way to go about this I am all ears, as I am not a dev but I am trying to learn to do it the right way..

btw... I just want to say thanks in advance as I greatly appreciate ya'll putting up with a newbie...
default.aspx.cs.txt
default.aspx.txt
0
Comment
Question by:AjarnJonesy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 39708810
You just need to tell it where you want to output to go.

something like

lblMessage.Text = proc.StandardOutput.ReadToEnd();

Open in new window

0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question