DOS find

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DOS find

DONALD PEDDER
    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).

    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. :-\

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

thanks,
    DONALD.

BIG DON's Home-page  - http://jedi.apana.org.au/~jims_son
Pedder Passer Rating - http://jedi.apana.org.au/~jims_son/PPR
AusNFL mailing-list  - http://jedi.apana.org.au/mailman/listinfo/ausnfl

"What I always wanted is to be accepted, not understood" - MAN RAY
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DOS find

Adam Naumowicz
On Fri, 3 Feb 2006, DONALD PEDDER wrote:

>     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).

You should try

IF ERRORLEVEL 1 echo blah, blah

In this way you will check if the errorlevel is greater or equal 1.

Hope this helps,

Adam Naumowicz

======================================================================
Department of Applied Logic            fax. +48 (85) 745-7662
Institute of Computer Science          tel. +48 (85) 745-7559 (office)
University of Bialystok                e-mail: [hidden email]
Sosnowa 64, 15-887 Bialystok, Poland   http://math.uwb.edu.pl/~adamn/
======================================================================


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DOS find

Tomas Hajny
In reply to this post by DONALD PEDDER
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.

Tomas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal