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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:45:23+00:00 2026-06-07T11:45:23+00:00

I am using ProcessStartInfo class to execute a batch file. But I am not

  • 0

I am using ProcessStartInfo class to execute a batch file.
But I am not so aware of using it properly.
When I execute a batch file can we track is there any error or not.
In my scenario, batch will start another process and it is successfully started it will be keep on executing. And if there is any error executing batch file it will exit. This is the code I am using.

I have to track both successfull start and failure as well.

internal bool ExecuteBatchFile(string fileName, int executionTime)
    {
        var exitCode = -1;
        var error = string.Empty;
        try
        {

            var hubStartInfo = new ProcessStartInfo
            {
                CreateNoWindow = false,
                FileName = fileName,
                UseShellExecute = false
            };

            var process = new Process { StartInfo = hubStartInfo };
            process.Start();
            process.WaitForExit(executionTime);

            if (process.HasExited)
            {
                exitCode = process.ExitCode;
                if (exitCode == 0)
                {
                    return true;
                }
                error = process.StandardError.ReadToEnd();
            }
            else
            {
                return true;
            }

            return false;
        }
        catch (Exception e)
        {
            return false;
        }
    }

Thanks

  • 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-07T11:45:26+00:00Added an answer on June 7, 2026 at 11:45 am

    See here for info on launching a process. Example 2 has info on monitoring the external process

    private void simpleRun_Click(object sender, System.EventArgs e)
    {
      System.Diagnostics.Process.Start(@"C:\listfiles.bat");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to execute a batch file using the Process class. This code
I am trying to execute a batch file from C# code using Process class.
I need to combine two video file using ffmpeg. Can you help me? I
In my Winform app, I execute a exe file using cmd Process. The exe
I am using a ProcessStartInfo to patch a file with a text file like
I'm using System.Diagnostics.ProcessStartInfo to set up the parameters for launching a process from a
When I try to start Firefox using Process.Start and ProcessStartInfo (.NET) everything seems to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
I'm running a process from inside a windows service using: ProcessStartInfo processStartInfo = new

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.