dvadura@watdaisy.UUCP (02/14/87)
Hi, I have a small problem and would appreciate it very much if someone has a solution. When using Microsoft C 4.0 the spawn... functions return nice exit codes from the tasks that you spawn. The problem lies when you run command.com with /C option. Is there some way to get command.com to return a proper exit code based on the exit code of the command it executed. This may not be easy since the command it executed can either be internal or external, and I'm not sure that the internal commands generate exit codes. On a similar vain is there a way to get the exit code as a result of executing the system() call from C. Any words of wisdom on this topic would be muchly appreciated. I'm sorry if this was talked about earlier, but I haven't seen the discussion before. I will post a summary of whatever responses I do receive. -thanks dennis -------------------------------------------------------------------------------- Dennis Vadura, Computer Science Dept., University of Waterloo UUCP: {ihnp4|allegra|utzoo|utcsri}!watmath!watdaisy!dvadura ================================================================================ -- -------------------------------------------------------------------------------- Dennis Vadura, Computer Science Dept., University of Waterloo UUCP: {ihnp4|allegra|utzoo|utcsri}!watmath!watdaisy!dvadura ================================================================================
ljz@well.UUCP (02/15/87)
In article <8137@watdaisy.UUCP> dvadura@watdaisy.UUCP (Dennis Vadura) writes: > ... When using Microsoft C 4.0 the spawn... functions return nice >exit codes from the tasks that you spawn. The problem lies when you run >command.com with /C option. Is there some way to get command.com to return >a proper exit code based on the exit code of the command it executed. Unfortunately, the answer is no. The spawn... function will return the exit code that command.com returns, which is "no error" as long as it found a command to run (irrespective of how the command actually performed). There is a partial solution to this, however: I have written my own "system" function that does the following: Search in the current directory for the command being run, appending .COM, .EXE, and .BAT as suffixes to the command (in that order). If the file is found, run it through spawn directly in the case of .COM or .EXE and through "command.com /c" in the case of the .BAT suffix. If the file isn't found, try the same thing in each directory in the user's PATH (accessible via getenv() in Microsoft C). If a file still isn't found, run the command through "command.com /c". In the cases where you are running a .COM or .EXE file through spawn the return code will be accessible. In the case where you had to send the command through "command.com /c" it won't, but this will only occur if the command is a .BAT file or an internal DOS command (such as DIR). For the sake of efficiency, you shouldn't use the "p" versions of spawn to run the command in this case (i.e., use 'spawnl' instead of 'spawnlp' and use 'spawnv' instead of 'spawnvp'). These "p" versions have code in them to test whether a PATH search is necessary, and since you will have already done one, that code would be superfluous. This should get you most of the way there with regard to return codes. If anyone wants this "system" function, email me at the below address. I'd have to dig it out of my archives and remove some program-specific stuff from it, so try the above yourself first ... it should be straightforward. If enough people really want it and don't want to try it themselves, I'll clean my version up and post it here. Lloyd Zusman Master Byte Software ...!hplabs!well!ljz