home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advos2 / ch12 / exec1.asm < prev    next >
Encoding:
Assembly Source File  |  1988-12-12  |  4.2 KB  |  112 lines

  1.         title   EXEC1.ASM Demo of synchronous child process
  2.         page    55,132
  3.         .286
  4. ; EXEC1.ASM   Demonstrates use of DosExecPgm to run
  5. ;             CHKDSK as a synchronous child process.
  6. ; Copyright (C) 1987 Ray Duncan
  7. ;
  8. ; Build:        MASM EXEC1;
  9. ;               LINK EXEC1,,,OS2,EXEC1
  10. ;
  11. ; Usage:        EXEC1 
  12. ;               
  13. ; Note:         File CHKDSK.COM must be available in PATH.
  14.  
  15. stdin   equ     0                       ; standard input handle
  16. stdout  equ     1                       ; standard output handle
  17. stderr  equ     2                       ; standard error handle
  18.  
  19. cr      equ     0dh                     ; ASCII carriage return
  20. lf      equ     0ah                     ; ASCII line feed
  21.  
  22.         extrn   DosExecPgm:far          ; reference to OS/2 API
  23.         extrn   DosExit:far
  24.         extrn   DosWrite:far
  25.  
  26. DGROUP  group   _DATA
  27.  
  28. _DATA   segment word public 'DATA'
  29.  
  30. objbuff db      64 dup (0)      ; receives name of dynamic link
  31. objbuff_len equ $-objbuff       ; causing DosExecPgm failure    
  32.  
  33.                                 ; argument strings for child
  34. argblk  db      'chkdsk',0      ; simple filename of child
  35.         db      ' *.*',0        ; simulated command tail
  36.         db      0               ; extra null byte terminates block
  37.  
  38.                                 ; receives return codes from child...
  39. retcode dw      0               ; termination code for child
  40.         dw      0               ; result code from child's DosExit
  41.  
  42. pname   db      'chkdsk.com',0  ; pathname of child program
  43.  
  44. wlen    dw      ?
  45.  
  46. msg1    db      cr,lf,'Unexpected OS/2 Error',cr,lf
  47. msg1_len equ $-msg1
  48.  
  49. msg2    db      cr,lf,'Exec function successful',cr,lf
  50. msg2_len equ $-msg2
  51.  
  52. _DATA   ends
  53.  
  54.  
  55. _TEXT   segment word public 'CODE'
  56.  
  57.         assume  cs:_TEXT,ds:DGROUP
  58.  
  59. main    proc    far
  60.  
  61.                                         ; run CHKDSK as a syn-
  62.                                         ; chronous child process...
  63.         push    ds                      ; receives module/entry
  64.         push    offset DGROUP:objbuff   ; point if dynlink fails
  65.         push    objbuff_len             ; length of object buffer
  66.         push    0                       ; 0=execute synchronously
  67.         push    ds                      ; address of argument block
  68.         push    offset DGROUP:argblk
  69.         push    0                       ; address of environment
  70.         push    0                       ; (0 = inherit parent's) 
  71.         push    ds                      ; receives child's exit
  72.         push    offset DGROUP:retcode   ; and termination codes
  73.         push    ds                      ; name of child program
  74.         push    offset DGROUP:pname
  75.         call    DosExecPgm              ; transfer to OS/2
  76.         or      ax,ax                   ; did child process run?
  77.         jnz     error                   ; jump if function failed
  78.  
  79. exit:                                   ; display success message...
  80.         push    stdout                  ; standard output handle
  81.         push    ds                      ; message address
  82.         push    offset msg2
  83.         push    msg2_len                ; message length
  84.         push    ds                      ; receives bytes written
  85.         push    offset wlen
  86.         call    DosWrite                ; transfer to OS/2
  87.  
  88.         push    1                       ; terminate all threads
  89.         push    0                       ; return success code
  90.         call    DosExit                 ; exit program
  91.  
  92. error:                                  ; display error message...
  93.         push    stdout                  ; standard output handle
  94.         push    ds                      ; message address
  95.         push    offset msg1
  96.         push    msg1_len                ; message length
  97.         push    ds                      ; receives bytes written
  98.         push    offset wlen               
  99.         call    DosWrite                ; transfer to OS/2
  100.  
  101.         push    1                       ; terminate all threads
  102.         push    1                       ; return error code
  103.         call    DosExit                 ; exit program
  104.  
  105. main    endp
  106.  
  107. _TEXT   ends
  108.  
  109.         end     main
  110.  
  111.