Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-10
1
Medium Priority
?
312 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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

688 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