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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:45:58+00:00 2026-06-14T11:45:58+00:00

I will use some CMD commands in my program and these commands might throw

  • 0

I will use some CMD commands in my program and these commands might throw some exceptions. And as you know, when an exception accours, CMD writes its own error message the screen. But, I want to write my own error message.

My question is this: Is there a way to block CMD messages and write only my own error messages?

P.S. This is not a complex program. It executes CMD commands using System().

Example:

Let’s say, the user can rename and copy any files in the program. As you know, if the user does not enter file’s path properly, an error message is showed on the screen. And I want that this error message never appears on the screen. Only my own error message is showed.

Thank you!

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

    It depends on your platform and the commands you are going to use. The usage of system() for calling console commands is by the way strongly discouraged by most people (it’s way to heavy for most purposes).
    I would suggest to you using CreateProcess() with the CREATE_NO_WINDOW flag and waiting for the process to exit with a call to WaitForSingleObject() and GetExitCodeProcess().
    This approach utilizes the fact, that most CMD command are executables, located somewhere in C:/Windows/....

    /*
     * Executes a program and returns it's exit code.
     *
     * TODO: Error checking should be added for
     *   CreateProcess()
     *   WaitForSingleObject()
     *   GetExitCodeProcess()
     */
    DWORD ExecCmdLine(TCHAR const* cmdline)
    {
        STARTUPINFO si;
        memset(&si, 0, sizeof(si));
        si.cb = sizeof(si);
        PROCESS_INFORMATION pi;
        memset(&pi, 0, sizeof(pi));
        ::CreateProcess(NULL, cmdline, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
        ::CloseHandle(pi.Thread);
        ::WaitForSingleObject(pi.hProcess, INFINITE);
        DWORD exitcode;
        ::GetExitCodeProcess(pi.hProcess, &exitcode);
        ::CloseHandle(pi.hProcess);
        return exitcode;
    }
    

    If you want to retrieve the output of the command you could also provide hStdOutput, hStdError in the STARTUPINFO structure and set STARTF_USESTDHANDLES in STARTUPINFO.dwFlags.
    You can even do other things in your own program while the command is executing (especially as you mentioned file copy). This one is done the C++ way:

    /*
     * TODO: Error checking should be added for
     *   CreateProcess()
     *   WaitForSingleObject()
     *   GetExitCodeProcess()
     */
    class AsyncCmd
    {
    public:
        AsyncCmd(std::string const& cmdline)
            : cmdline(cmdline),
              processHandle(NULL)
        {
        }
        ~AsyncCmd()
        {
            if (this->processHandle != NULL)
                ::CloseHandle(this->processHandle);
        }
        // Starts the execution of the commandline.
        void Start(HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE), HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE))
        {
            STARTUPINFO si;
            memset(&si, 0, sizeof(si));
            si.cb = sizeof(si);
            si.dwFlags = STARTF_USESTDHANDLES;
            si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
            si.hStdOutput = hOut;
            si.hStdError = hErr;
            PROCESS_INFORMATION pi;
            memset(&pi, 0, sizeof(pi));
            ::CreateProcess(NULL, this->cmdline.c_str(), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
            ::CloseHandle(pi.hThread);
            this->processHandle = pi.hProcess;
        }
        // Blocks until execution is finished and returns the exit code.
        DWORD ExitCode()
        {
            ::WaitForSingleObject(this->processHandle, INFINITE);
            DWORD exitcode;
            ::GetExitCodeProcess(this->processHandle, &exitcode);
            return exitcode;
        }
    private:
        AsyncCmd(AsyncCmd const&);
        AsyncCmd& operator=(AsyncCmd const&);
        std::string cmdline;
        HANDLE processHandle;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im writing c# app in VS2008 that will use some reports. My question: how
If i use some really simple code like : $('#elm').tipTip(); It will do what
I need to import some Excel spreadsheets into Java objects. I will use POI
Is it possible to use COUNT in some way that will give me the
I have seen some instances where people will say you have to use JS
So when you use scaffolding Rails will kick out some layouts that are xhtml
I will use std::map<int, A> A is a class and I have to prevent
I will use (again) the following class hierarchy: Event and all the following classes
I will use the following javascript to display a Google Map Window in a
I will use quickaction for a listview. I use this example for quickaction: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

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.