July 22nd, 2003, 05:25 PM
Newbie Capture system() return code
I'd like to know how to capture the return code from the system function and have my program return it to the shell.
Take this program for example. I'd like to be able to run this .exe from the command line and check the errorlevel using %errorlevel%
system("Net Use J: \\\\Server\\Share /persistent:no");
So, from the command line
In this case the net use command returned error 85, "drive already in use."
July 22nd, 2003, 06:34 PM
If system() runs successfully, then the return value should be the %errorlevel% you want.
From Visual C++6 help page for system (my emphasis):
The Remarks section says that if system is passed a NULL, then it will only check that the command interpreter exists.
July 22nd, 2003, 10:52 PM
Why not just return the value from system() instead of returning 0 in main().
return system("Net Use J: \\\\Server\\Share /persistent:no");
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
July 23rd, 2003, 12:27 PM
Yes, that's what I was looking for! Like I said, I'm very new to C++, and the obvious still isn't so obvious. Thanks!