1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Executing another exucutable file using IntDos()

Discussion in 'C++' started by albert_sps, Mar 18, 2008.

  1. albert_sps

    albert_sps New Member

    Mar 18, 2008
    Likes Received:
    Trophy Points:
    :confused: I´m trying to load and execute .COM files without using Exec function, only using int 21h sys calls to DOS.

    Trouble appends when I send parameters after filename in prompt:

    Ejemplo: c:\load comfilename [commandline]

    This is the code, wich doesn run properly, thus when execute intdos() functions doesn´t respond:
    // load.c
    #include <stdio.h>
    #include <dos.h>
    #include <stdlib.h>
    #include <sys\types.h>
    int main(int argc, char near  *argv[ ])
       int len, i, j, retorna, tam;
       union REGS regs;
       char f1[20] = "0000000000000000000\0";   // FCB1 in blank
       char f2[20] = "0000000000000000000\0";
       // parameters block to asign to BX
       struct  parametros {
          short int segmento;
          char* lineacomando;
          char* fcb1;
          char* fcb2;
       } par;
       char *cmd;   // commandline
       cmd[0] = (char) strlen(argv[2]);
      // set parameter block
       par.segmento = 0;
       par.lineacomando = cmd;
       par.fcb1 = f1;
       par.fcb2 = f2;
       regs.h.ah = 0x4b;
       regs.h.al = 0x00;
       regs.x.dx = (unsigned) argv[1];
    [B]   regs.x.bx = (unsigned int) &par;[/B]
       retorna = intdos(&regs, &regs);
       if (!(regs.x.cflag ? retorna : 0)) 
                { printf("CARRY FLAG IS CLEAR\n"); };
       printf("Exucute complete!: %s", argv[2]);
       return 0;
  2. albert_sps

    albert_sps New Member

    Mar 18, 2008
    Likes Received:
    Trophy Points:
    I have used this information concerned to this topic:

    Function (ah): 4Bh
    Entry parameters: ds:dx- pointer to pathname of program to execute
    es:bx- Pointer to parameter block
    al- 0=load and execute 1=load only 3=load overlay.

    The execute (exec) function is an extremely complex but at the same time very useful operation. This command allows you to load or load and execute a program off of the disk drive. On entry into the exec function the ds:dx registers contain a pointer to a zero terminated string containing the name of the file to be loaded or executed es:bx points at a parameter block and al contains zero or one depending upon whether you want to load and execute a program or simply load it into memory. On return if the carry is clear then DOS properly executed the command. If the carry flag is set then DOS encountered an error while executing the command.

    The filename parameter can be a full pathname including drive and subdirectory information. "B:\DIR1\DIR2\MYPGM.EXE" is a perfectly valid filename (remember however it must be zero terminated). The segmented address of this pathname is passed in the ds:dx registers.

    The es:bx registers point at a parameter block for the exec call. This parameter block takes on three different forms depending upon whether a program is being loaded and executed (al=0) just loaded into memory (al=1) or loaded as an overlay (al=3).

    If al=0 the exec call loads and executes a program. In this case the es:bx registers point at a parameter block containing the following values:

    Offset Description
    0 A word value containing the segment address of the default environment
    (usually this is set to zero which implies the use of the standard DOS
    2 Double word pointer containing the segment address of a command line string.
    6 Double word pointer to default FCB at address 5Ch
    0Ah Double word pointer to default FCB at address 6Ch
    The environment area is a set of strings containing default pathnames and other information (this information is provided by DOS using the PATH SET and other DOS commands). If this parameter entry contains zero then exec will pass the standard DOS environment on to the new procedure. If non-zero then this parameter contains the segment address of the environment block that your process is passing on to the program about to be executed. Generally you should store a zero at this address.

Share This Page