The first thing you need to do is work out whether the programmers of the program you're trying to run are 'int main' or 'void main' programmers.
Because if its the latter, you're sunk
Here's a short batch file to check what the exit status is
Code:
@echo off
prog.exe
IF ERRORLEVEL 1 echo Gak!!!
If it ever prints "Gak" for any normal program exit, or doesn't print "Gak" for any fail exit, then you're dealing with a bunch of void main programmers who don't know how to return a proper status back to the calling environment (your program in this case).
Ok, test time
1. compile this program as mystat.exe
Code:
#include <stdio.h>
int main ( int argc, char *argv[] ) {
int status = atoi( argv[1] );
printf( "Returning a status of %d\n", status );
return status;
}
2. compile this program as teststat.exe
Code:
#include <stdio.h>
int main ( ) {
char cmd[100];
int i,res;
for ( i = 0 ; i < 10 ; i++ ) {
sprintf( cmd, "mystat.exe %d", i );
res = system( cmd );
printf( "Actual status=%d, should be %d\n", res, i );
}
return 0;
}
If you don't get
Returning a status of 0
Actual status=0, should be 0
Returning a status of 1
Actual status=1, should be 1
etc,
Then something is broke