Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3793096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:43:23+00:00 2026-05-19T12:43:23+00:00

For a project I am building a new front end for an old Batch

  • 0

For a project I am building a new front end for an old Batch script System. I have to use Windows XP and C# with .Net. I don’t want to touch this old Backend system as it’s crafted over the past Decade. So my Idea is to start the cmd.exe Program and execute the Bash script in there. For this I will use the “system” function in .Net.

But I also need to read the “Batch script commandline Output” back into my C# Program. I could redirect it into a file. But there has to be a way to get the Standard Output from CMD.exe in into my C# Program.

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:43:24+00:00Added an answer on May 19, 2026 at 12:43 pm

    Your ways are good. But you only get the whole Output at the end. I wanted the output when the script was running. So here it is, first pretty much the same, but than I twised the output.
    If you have problems look at:
    http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

    public void execute(string workingDirectory, string command)
    {   
    
        // create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
        // Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
        System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(workingDirectory + "\\" + "my.bat ", command);
    
        procStartInfo.WorkingDirectory = workingDirectory;
    
        //This means that it will be redirected to the Process.StandardOutput StreamReader.
        procStartInfo.RedirectStandardOutput = true;
        //This means that it will be redirected to the Process.StandardError StreamReader. (same as StdOutput)
        procStartInfo.RedirectStandardError = true;
    
        procStartInfo.UseShellExecute = false;
        // Do not create the black window.
        procStartInfo.CreateNoWindow = true;
        // Now we create a process, assign its ProcessStartInfo and start it
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
    
        //This is importend, else some Events will not fire!
         proc.EnableRaisingEvents = true;
    
        // passing the Startinfo to the process
        proc.StartInfo = procStartInfo;
    
        // The given Funktion will be raised if the Process wants to print an output to consol                    
        proc.OutputDataReceived += DoSomething;
        // Std Error
        proc.ErrorDataReceived += DoSomethingHorrible;
        // If Batch File is finished this Event will be raised
        proc.Exited += Exited;
    }
    

    Something is off, but whatever you get the idea…

    The DoSomething is this function:

    void DoSomething(object sendingProcess, DataReceivedEventArgs outLine);
    {
       string current = outLine.Data;
    }
    

    Hope this Helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's imagine I already have a project building .NET 3.5 assembly. Now I want
I'm building a new front end for an existing forum project, and I'm undecided
I have been tasked with building a new web project from scratch, with the
I am totally new in building Visual Studio Project through a script, so feel
I'm building a new project using Seam 3. I don't understand what the difference
I have recently joined a new developing project building a thick client application using
I am building a new project with Castle ActiveRecord and have a little technical
I'm about to start building a new asp.net project, and I'm just starting out
I am getting ready to start building a new web project in my spare
I'm going to start a new project that's building web apps from scratch. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.