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.
//***************************************************
// 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);
const
UnixListCommand = 'ls -l';
OtherListCommand = 'dir';
begin
if UnixPlatform then
exec(UnixListCommand, '*.pas')
else
exec(OtherListCommand, '*.pas');
if exitcode <> 0 then
writeln('Error listing directory', exitcode)
end.
Operating Systems: All
Standard Pascal: No