The exec procedure


The exec procedure executes a command by passing it to the command processor. The built-in variable exitcode contains the numeric code returned by the command processor to indicate whether an error occured. If return value of zero means that no error occured while executing the command, and any other return value identifies the particular error that occured. The values used by the command processors of different operating system, to identify which error occured, are not standardized and is not documented here.


  1. The first parameter is an expression of string type or char type, and is the command to execute.
  2. The second parameter is an expression of string type or char type, and contains the arguments used by the command. If no arguments are used by the command then this parameter is an empty string.


   // This program lists all the files ending with .pas
   //  in the current diectory using the built-in
   //  procedure "exec".
   // Basically the program determines whether it is running
   //  under a Unix-like platform or not and passes
   //  the approprate list command to "exec" along
   //  with the "*.pas" argument so that only files
   //  ending with .pas are listed.
   program dirpas(output);
      UnixListCommand = 'ls -l';
      OtherListCommand = 'dir';

      if UnixPlatform then
         exec(UnixListCommand, '*.pas')
         exec(OtherListCommand, '*.pas');
      if exitcode <> 0 then
         writeln('Error listing directory', exitcode)


Operating Systems: All
Standard Pascal: No