If I have understood what you asked, perhaps you want to capture the so called “exit codes”. If so, the method to do that is machine dependent.
From the point of view of an executables, once it has terminated…, well, it has terminated :-)
Sorry for the tautology, but what I mean is it can’t help you any more: the operative system will just dump it from memory (unless of course it’s a
daemon or
terminate-and-stay-resident program, or however you call it, which might no more answer to commands, but be still in memory).
But programs can send back an ending code to the operative system when they terminate, and the operative system can catch it.
In a Microsoft environment the simplest method to catch those exit codes is probably by means of a ‘batch’ file, a script with extension .bat.
Provided you have a program like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <cctype>
#include <iostream>
#include <string>
char getFirstCharFromCin();
int main()
{
return static_cast<int>(getFirstCharFromCin());
}
// Might return a warning about missing return value
char getFirstCharFromCin()
{
std::cout << "Please enter a character included in the English alphabet: ";
for(std::string line; std::getline(std::cin, line); /**/) {
if(!std::isalpha(line.front())) {
std::cout << "Dude, I need a character!\n"
"Please enter a character included in the English alphabet: ";
continue;
}
return line.front();
}
}
|
And you compile it into an executable named
misterh.exe, you can work out a batch file like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
@echo off
misterh.exe
if %ERRORLEVEL% equ 108 (
echo It should be a lowercase '22'
goto THEEND
)
if %ERRORLEVEL% equ 76 (
echo 22
goto THEEND
)
echo Unmanaged exit code.
:THEEND
echo.
echo Execution complete
echo.
|
The above script executes misterh.exe and evaluates its exit code.
In a Linux environment things would likely be easier and more flexible.