Q:

Command processor vs Console in C++

I am creating a C++ console application and want to check whether the command processor is available:
if (!system(NULL))  //check to see if command processor is available
{
    fprintf(stderr, "Error: Command processor not available\n");
    exit(EXIT_FAILURE);
}

My question is, can a console app exist or work without having a command processor attached to it? If when a console is created, it is always paired somehow with a command processor, then the code above would be redundant.
Otherwise, the console window will appear, the program will run normally, but I just can't use system().

A:

If you have a console application, then you're going to be running your program from inside a command processor. Therefore, a command processor is available in the context of your program.
It is probably possible with some trickery to "hide" said processor from your process, but I don't know how to do so on any OS.
More generally, though, since C++ is an abstract "multi-purpose" language, in theory it is conceivable that for some given program P in some environment E a command processor is not available, but in practice I can't think of an example. Perhaps when, say, writing a kernel module?
Overall I would probably not bother with this check unless you already had reason to believe that there may be something "unusual" about the execution environment — you need to handle errors generated by your "real" system calls anyway.
Still, can't hurt.

