[fpc-pascal] DOS find

Tomas Hajny XHajT03 at mbox.vol.cz
Sat Feb 4 19:51:17 CET 2006

On 3 Feb 06, at 17:19, DONALD PEDDER wrote:

>     I'm having issues with the following 2 lines of code...
> Exec(GetEnv('COMSPEC'),'/c find "'+paramstr(1)+'" qbslist.txt');
> writeln('return code ',lo(DosExitCode));
>     Even when nothing is found I still get return code 0! :-\ I need
>     to 
> know how many strings were found (or at a minimum if none were found,
> which should theoretically have a non-zero return code. I know it does
> in NT, but at home in DR-DOS/MS-DOS "echo %errorlevel%" isn't working,
> so I can't see directly what return code it's giving, though I'm
> pretty sure it wouldn't be 0 if nothing was found).

As you probably know, FIND is an external command 
(standalone executable file FIND.COM or FIND.EXE -
 different DOS versions use either .COM or .EXE 
format). Depending on the exact DOS/VDM version, 
COMMAND.COM doesn't always return the exitcode of 
other executables (even if COMMAND.COM is started 
with /c parameter). This means that you should 
preferably try to run the executable file 
directly instead of starting it indirectly using 
the command shell.

Note that you have to provide the full path to 
the started programs, so you have to locate 
FIND.COM/.EXE on the local drive first - either 
by letting Dos.FSearch to check your PATH (but 
you'd have to try it twice, once for FIND.COM and 
once for FIND.EXE) or by coding it yourself.

>     Ideally I'd rather let FP do the search (so that the code isn't
> OS-dependent - one day, when I get around to it, I'd like to compile
> this for Unix too), but I can't find anything like that. In the
> documentation I can find stuff for string manipulations, and stuff for
> file manipulations, but nothing for finding a string in a set of
> files. :-\

Indeed, you have to combine these together 
yourself. ;-)

>     I'm using 1.0.10 (seeing as how 2.0.0 doesn't support DOS from the
> comments I've seen on list).

2.0.2 compiler works quite well under GO32v2, but 
there are some issues with the IDE.


More information about the fpc-pascal mailing list