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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:06:31+00:00 2026-05-15T20:06:31+00:00

I’m attempting to run a series of commands programmatically, read the error codes, and

  • 0

I’m attempting to run a series of commands programmatically, read the error codes, and detect if these codes indicate success or failure so I can respond accordingly.

Currently my commands are using psexec which then launches robocopy. I’ve noted that while most commands return an error code of 0 if the program is successful, robocopy is odd in that it returns values in the range of 0-8 even if the operation is successful, so I am adding some extra logic in my error detection to note when robocopy returns an error code which otherwise suggests a failure.

The problem is that in this same set of commands I’m using PSExec to launch various other executables and batch files, so I need an error detection solution that allows me to know when robocopy is the one returning these error codes or if it’s PSExec because an error code of 5 in robocopy is fine usually whereas an error code of 5 in PSExec says that access is denied.

So my question is, how do I know which program has returned the error code? I’m using c# .NET 4.0, and I’m using the Process class to programmatically launch these programs. I set the program name as psexec, and the arguments include the robocopy or other programs. I then run, wait for the exit, and store the error code, then attempt to parse it.

What do you all suggest?

Here is a code snippet:

foreach (var command in commands)
        {
            // TODO: Add exception handling
            string processName = command.Split(delimiters).ToList().ElementAt(0);    // split up command into pieces, select first "token" as the process name
            string commandArguments = command.Replace(processName + " ", ""); // remove the process name and following whitespace from the command itself, storing it in a new variable
            Process commandProcess = new Process(); // declare a new process to be used
            commandProcess.StartInfo.FileName = processName;    // add file start info for filename to process
            commandProcess.StartInfo.Arguments = commandArguments;  // add file start info for arguments to process
            commandProcess.StartInfo.UseShellExecute = false;  // skip permissions request
            commandProcess.Start();   // start process according to command's data
            commandProcess.WaitForExit();   // wait for the process to exit before continuing
            bool commandSuccessful = ParseCommandErrorCode(commandProcess, commandProcess.ExitCode);    // grab error code
            if (!commandSuccessful)
            {
                // ERROR! abort operation and inform the user of the last completed operation, and how many commands have not been run
            } // end if
            Console.WriteLine("Error code: {0}", commandProcess.ExitCode);    // print error code
            commandProcess.Close(); // close process
        } // end foreach
  • 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-15T20:06:32+00:00Added an answer on May 15, 2026 at 8:06 pm

    Haven’t you already answered your own question? You will have to match the error code to success or failure for each utility. commandProcess.StartInfo.FileName will tell you if the utility launched was robocopy or PSExe. When parsing the error code, map the value to success or failure depending on the name of the file.

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

Sidebar

Related Questions

No related questions found

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.