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 9112689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:47:42+00:00 2026-06-17T03:47:42+00:00

I am trying to run a Batch file from .net/c# using System.Diagnostics.Process. Somehow it

  • 0

I am trying to run a Batch file from .net/c# using System.Diagnostics.Process. Somehow it does not execute xcopy command of the Batch file.

Sample Batch File:

#copy test to test2 including sub directories
xcopy c:\test\ c:\test2 

C# code:

    public void RunMSIBatchFile(string _workingDirectory, string batchFileName)
    {
        var process = new Process
        {
            StartInfo =
            {

                UseShellExecute = false,
                RedirectStandardOutput = true,
                WorkingDirectory = _workingDirectory,
                FileName = _workingDirectory + batchFileName,
                CreateNoWindow = true,
                RedirectStandardError = true
            }
        };

        process.OutputDataReceived += ProcessOutputDataReceived;
        process.Start();
        process.BeginOutputReadLine();
        process.WaitForExit(Convert.ToInt32(CommandTimeOut.TotalMilliseconds));
    }

If I change UseShellExecute to true then it works but then there seems to be no way to capture standard output.

Has anyone faced such problem?

  • 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-06-17T03:47:43+00:00Added an answer on June 17, 2026 at 3:47 am

    I’ve tested your exact code, and appear to be able to receive data just fine. However, since the read occurs asynchronously, it is possible for WaitForExit(...) to return before you have read all of the data. It appears that the end of the data is signalled by the Data property of the DataReceivedEventArgs passed to the OutputDataReceived event handler being null.

    It is also worth noting that if xcopy requests input from the user (e.g. in the case of a file with the same name existing in the destination) it appears that no data is returned. You may want to check for this in your batch file, or also handle data from the Standard Error stream.

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

Sidebar

Related Questions

I'm trying to run a batch file on a server from an ASP.NET page.
I am trying to execute a batch file using the Process class. This code
I am trying to run a batch file automatically during a build from a
When i am trying to run some queries from the batch file i am
I am trying to use iexpress to run my batch file which will execute
I'm trying to run a batch file that exists in one folder, from a
I'm trying to run a batch file on a server via an ASP.Net page,
I am trying run a batch file from my java codes, but unfortunately I
I'm trying to run this batch file from a windows service (running as my
I'm trying to run a batch file, as another user, from my web app.

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.