Solved

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

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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

626 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