/* Execute DOS .EXE file with standard handles redirected. Accept redirection arguments of the form: e -r file command : stdout and stderr to file. ( space opt. ) e -r #hnd command : stdout and stderr to handle hnd. ( space req.) e -rhnd file command : handle hnd to file. e -rhnd1 #hnd2 command : handle hnd1 to handle hnd2. Same as above with -a instead of -r will append. Standard handles are: 0 - standard input ( not useful here ) 1 - standard output. 2 - standard error. 3 - standard auxillary ( usually serial port ). 4 - standard printer ( usually parallel port ). Examples: e -r out masm test,,test; -- send all standard output and standard error output to the file 'out'. Note that due to the difference in the way C stream level stdout and stderr are handled, 'out' may contain output in a different order from that seen on the screen. e -r2 errors masm test; -- send all standard error output to the file errors. Standard out still goes to the console. e -r1 out -r2 errs masm test; -- send standard output to file 'out'. -- send standard error to file 'errs'. e -r4 #1 masm test; -- send printer output to console. */ #include #include #include #include #include #include #include #include /* Error return codes */ #define NO_ARGS 1 #define DUP 2 #define EXEC 3 #define OPEN 4 #define BAD_SWITCH 5 /* Known handles */ #define STDOUT 1 #define STDERR 2 #define SWITCHARS "-/" #define DIGITS "0123456789" #define FALSE 0 #define TRUE -1 int Redirect(); /***** ************ ***********************/ main( argc, argv ) int argc; char *argv[]; { int argcount = 1; if ( argc < 2 ) { puts( "Usage is: e [<-r|-a[hnd] filename|hnd>] <.EXE file> " ); exit( NO_ARGS ); } while( strcspn( argv[argcount], SWITCHARS ) == 0 ) argcount += Redirect( argv + argcount ); if ( execvp( argv[argcount], argv + argcount ) == -1 ) { printf( argv[argcount] ); perror( ": Exec Error" ); exit( EXEC ); } } /********* ********* ********** *************/ int Redirect( argv ) char *argv[]; { char * cur = argv[0] + 1; /* Start looking at second char */ int handle1 = -1; /* Handle directed from */ int handle2 = -1; /* Handle directed to */ int append = FALSE; /* Append to output file? */ int numargs = 2; /* Number of command line arguments used */ int index; /* Used for distinguishing cases */ switch ( *cur ) { case 'a' : append = TRUE; case 'r' : cur++; break; default : printf( "Mal-formed switch: '%s'\n", cur - 1 ); exit( BAD_SWITCH ); } index = strspn( cur, DIGITS ); /* Find first non-digit */ if ( cur[ index ] == '\0' && index ) /* If it's end-of-string, and string len > 1, then we're looking at -r# filename */ { if ( !sscanf( cur, "%d" , &handle1 ) ) { printf( "Bad handle in switch expression: '%s'\n", cur ); exit( BAD_SWITCH ); } cur = argv[1]; } else { /* If first char is nul, we're looking at -r filename */ if ( *cur == '\0' ) cur = argv[1]; else numargs = 1; /* Else we're looking at -rfilename */ } if ( *cur == '#' ) /* handle2 is in command string */ { if ( !sscanf( cur + 1, "%d", &handle2 ) ) { printf( "Bad handle in switch expression: '%s'", cur + 1 ); exit( BAD_SWITCH ); } } else /* handle2 must be generated with open() */ if ( (handle2 = open( cur , O_WRONLY | (append ? O_APPEND : O_TRUNC ) | O_CREAT, S_IWRITE )) == -1 ) { printf( cur ); perror( ": Open Error" ); exit( OPEN ); } if ( !(handle1 == -1) ) /* Handle to redirect is specified */ { if ( dup2( handle2, handle1 ) == -1 ) { perror( "Dup2 Error" ); exit( DUP ); } } else { if ( dup2( handle2, STDOUT ) == -1 ) { perror( "Dup2 Error on Standard Out" ); exit( DUP ); } if ( dup2( handle2, STDERR ) == -1 ) { perror( "Dup2 Error on Standard Error" ); exit( DUP ); } } return numargs; } MZ2 w/t**UdVF~}(PPpPNFFPcFP^v03 t֋FFP^v0@u$^v0PP^]U V^@FFFFF؊=at=rtHPPcPFFPvF؋v8u9 t5FPPV uvPP=^GF ^?tF^?#u*FPP@P@ uVF@PP;P~t Pv@F@uvP|P~tvvt@uM"7Pv_@u-P>PsPv;@uHP#include main() { fprintf( stdout, "Hello, standard out\n" ); fprintf( stderr, "Hello, standard error\n" ); fprintf( stdaux, "Hello, standard aux\n" ); fprintf( stdprn, "Hello, standard prn\n" ); } MZ  qe45f|U39\PPqPP}PPoPPa]Y+r ;|r"06+rׁĮs6&6&ƱH6~0!<s*3P !DOS 2.0 or later required $6+۴J!6+3bn n +3Pz error 2000: Stack overflow error 2003: Integer divide by 0 error 2002: Floating point not loaded 2@!PE#;)^UWVv_FPvvvV^_]U n t ~uF%!pnFL!UVv@u6D u0DRu!DDƇRDDhtuZDuTDRuE>tDDDƇRd멸P D t DL3^]UVv~u9Du V 3h~tbuDPX  t V 0tu8V $DDttA d DƇR3D^]UV3522U5u&4 t 6%@!25^]UWV6 PP46  t<u<t9< FGF=u2^FNG~u^_]ûzsS[CCûD!r €t@Kyô0!Î&6,5!%!6p"6r36ns66vڻ6nù3t>!CU, vB]UbWVvFF<uI<%t 3 2<-u'<+u < u >u FP uVP<.uFVPr. PP3PۋA>t F=%tG=u+PV^_]UWV~ t>tWFV)>tFF FV>t F FtF36>u*~}$~ u-FFV؃ډFVFFvWvv>t W+ȉN0FFN >tu t ~u3PU^_]UWV ~tF3F uF0v >t 9s6>+>uWVvm>tW^_]U>F>u66v6v ~gt~Gu>u>t 6>t>u 6v tvY t3P$]U3V>u8O|F7* 6v@u^]UQWV>uQv ~J3O|?*66@uN ƃ>uF^_]UWVv~>uL5O|و*6P)@uFO uă>uF^_]U ~WV63FF>VF++~>u<-u>0u P>0t ~>t~tF^>tFp>u&W~t ~u4>t ~uCvV>t  Wt^_]U3>t+ P]U30P>u>tXxP]UjWVv<*u?F:3<0|3<9.9>u <0u0ȃ0<0|<9~^?^_]UV7 8FuF<u3^]Ï<3&>reP,3ы&8uы&GA:t<"t< t< uX+O+ tB[%+ $+C P܋ t =tNV8 t )uEڪKK;sD u&&<< t< <"u t<"u }\uOuÏ>3ɋI6, tEuE@$ϋ3I ~EE uN&&>UWVvDtD@t L DuLd3D~DuDRt0<+| ~WtDPFD@D\FhDuLu+DP u3@DDƇR뺸PD tL띀LWFPDP F9~t)F*^_]ûsS[CCûsS[CCUWVv3V|D$<uerrors.dat will send the Assembler's error messages to 'errors.dat', instead of to the console. However, the above command will not redirect error messages with MASM 4.0. MASM 4.0 sends error messages to standard error, one of the MS-DOS standard device handles. It is not possible to redirect output from MASM 4.0 because MS-DOS does not allow redirection of standard error from the console. This disk contains a utility which allows you to run MASM with standard handles redirected. The files on this disk are: WRITE.C WRITE.EXE E.C E.EXE README The following is a description of the files and their purpose: WRITE.EXE Allows you to determine where information for standard output, standard error, standard auxiliary (usually serial port), and standard printer (usually parallel port) will be directed. The source code for the program is WRITE.C. E.EXE Executes a program after redirection of standard handles has taken place. The program accepts arguments of the form: e -r file command stdout and stderr to file e -r #hnd command stdout and stderr to handle hnd e -rhnd file command handle hnd to file e -rhnd1 #hnd2 command handle hnd1 to handle hnd2 To append in addition to redirecting, use -a instead of -r. The standard handles are: 0 - standard input (not useful here) 1 - standard output 2 - standard error 3 - standard auxiliary 4 - standard printer The following are examples of command lines: e -r out.dat masm test,,test; send all standard output and standard error output to the file 'out.dat'. Note that due to the difference in the way C stream level stdout and stderr are handled, 'out.dat' may contain output in a different order from that seen on the screen. e -r #4 masm test,,test; send all standard output and standard error output to the standard printer e -r1 out.dat -r2 errs.dat masm test; -- send standard output to file 'out.dat' -- send standard error to file 'errs.dat' e -r4 #1 masm test; send standard printer data to standard output (console) e -r1 nul -a2 errlog.dat -r4 out.dat masm test; -- throw away standard output -- append standard error to errlog.dat -- send standard printer into out.dat The source code for the program is E.C.