PDA

View Full Version : windows ERRORLEVEL


Whiteknight
06-27-2004, 05:13 PM
I'm writting a C++ program that manipulates several settings on my winXP computer, one of them being the IP address settings.

I reset all the IP address values, and then I use a system call to ping an external server. for example:

system("ping www.google.com");


now, i want to capture the errorlevel of the ping program, and use that in some decision structures later in the program (ie if the ping fails, i do one thing, and if the ping succeeds i do another).

in a batch script, I could do the following:


ping www.google.com > NUL
if ERRORLEVEL 1 goto 10
if not ERRORLEVEL 1 goto 20


but I want to do this from a C++ program.

is there a way that i can caputure the value of ERRORLEVEL from C++ (with a getenv() function perhaps?) or do i need to use more system calls?

stuka
06-27-2004, 08:07 PM
What does ERRORLEVEL contain? Is it the exit code of the process? If so, the return value from system() is the same. If not, perhaps getenv() is the best first attempt.

Whiteknight
06-27-2004, 11:27 PM
first i tried the getenv() but that didnt work, I think that ERRORLEVEL is a local variable, and not a global one like i first thought. I think it is the exit code of the process, so i will try taking the return value of system().

thanks.

stuka
06-28-2004, 11:12 AM
Well, just did a quick Google search, and apparently the ERRORLEVEL (from dos) IS the program return code.

Whiteknight
06-29-2004, 06:35 PM
yeah, thanks for the help stuka. i thought it was something more complicated, but it is just the return code.