Solved

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

Posted on 2013-12-10
1
306 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

777 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