Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
system() always returns 0?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Kenny McCormack, post: 4081736"] Kiki has already given you the "CLC standard" answer, which is, of course, a) entirely correct in all its particulars and b) entirely useless. Now, onto a (hopefully) useful answer. As far as I know, this has never worked correctly (for suitable assumptions about what "correct" means) under DOS/Windows. I.e., the returned value returned by COMMAND.COM/CMD.EXE/whateverElseFromMS tells you only that COMMAND.COM itself succeeded (which is true 99.999999% of the time). This behavior is unlikely to ever change in the Windows product line. In Unix, it does work correctly - that is, sh "passes down" the value returned by the command: $ sh -c 'ls ksdfjh';echo $? ls: ksdfjh: No such file or directory 1 $ P.S. Once, a long, long time ago, I wrote a DOS device driver to address this problem. It was a little "hinky", but it did work. Was rather cool, in its own little way. P.P.S. The FGA for this sort of problem is to somehow hack the command line that you run so that it indicates the status in some "out of band" way, such as: system("yourcommand & if errorlevel 1 echo Failed > atmpfile"); Note that in Unix, you could do: echo $? > atmpfile, but the seemingly equivalent DOS syntax (%errorlevel%) just doesn't quite do it... HTH [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
system() always returns 0?
Top