Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

C's system() & COMMAND.COM (Developers)

posted by bretjohn(R) Homepage E-mail, Rio Rancho, NM, 18.09.2014, 18:14

Unfortunately, INT 2Eh has this problem (quoting from the link provided): "results are unpredictable if invoked by a program run from a batch file because this call is not reentrant and COMMAND.COM uses the same internal variables when processing a batch file".

I really don't think there's a way to do what you're trying to do and have it return consistent results. E.g., I'm not sure if/how ErrorLevels are even returned by internal commands (or even if internal commands terminate with an INT 20h or INT 21.4C). I'm not sure exactly how batch files terminate, either, but what your system() call should return is the ErrorLevel of the batch file itself (which doesn't really exist AFAIK), and not just the ErrorLevel of the last command the batch file issued. And, if you do things in two different ways (invoking %COMSPEC% only if it doesn't have an explicit COM or EXE extension), then you will be able to return a valid ErrorLevel in some cases (COM or EXE) and not in others (every other case). As the link I provided earlier indicates, even if an explicit COM or EXE extension is provided, but you are using an early DOS version (earlier than v4), you have to ignore the extension if you want your program to do the same thing DOS would do.

The idea of two different calls (one that invokes %COMSPEC% and can't return valid ErrorLevels, and one that doesn't invoke %COMSPEC% but can return valid ErrorLevels) may be a valid approach that you can actually implement successfully and consistently. The "generic" system() call as defined in the C standard would seem to be the one that DOES invoke %COMSPEC%.


Complete thread:

Back to the forum
Board view  Mix view
15297 Postings in 1378 Threads, 254 registered users, 7 users online (0 registered, 7 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum