Solved

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

Posted on 2013-12-10
1
304 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now