[fpc-pascal]How to call DOS BATCH file?

Aitor Santamar�a aitor.sm at wanadoo.es
Tue Feb 5 10:54:56 CET 2002


Hi,

An .EXE file is a intel-machine readable file, whereas a .BAT file is a COMMAND.COM-machine readable file. Therefore, you need to call the appropiate "machine" to run this program.
Usually,

COMMAND /C commandline

opens the COMMAND interpreter (or machine), then executes commandline and exits.
Therefore, you should do something like:

Exec (getenv('comspec'), '/C '+MyBatchFileName);

as it is more appropiate to look for COMMAND.COM from the COMSPEC DOS variable than assuming it's at C:\

(this would work on 99% DOS machines, where the SHELL= is COMMAND.COM or compatible).

Regards,
Aitor

> Hello all,
> I've a problem. If I try to call DOS .exe program via Exec(...), it works fine. But
> if I try to call some batch file in the same path (this batch file calls another exe file),
> it doesn't work. It writes, that the specified file isn't name of executable or batch file
> (instead of the name of file it maybe writes the character '-' or space). The batch file
> exists, of course :-))) and can be run by hand. Location of batch file is OK too, because
> another .exe file from the same location can be run via Exec without any problem.
> 
> I try it on Win2K, FPC 1.0.2 target Win32.
> 
> Can anybody help me, please, correct this problem?
> 
> Sources:
> ------------------
> testik.pp:
> -----------
> Program testik;
> uses dos;
> begin
>   Exec('d:\test.bat','');  {it would call the test.bat batch file}
>   readln;                 {wait for pressing Enter}
> end.
> 
> d:\test.bat: (I've place it to root of D:, on other location is the same problem)
> -------------------
> d:\Simulator1.exe
> 
> 
> (batch calls the "simulator1.exe" file, by hand it works,via FPC doesn't)
> 
> Thanks for your advice and wish a nice day
> 
> Martin
> 
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 
> 
_____________________________________________________________________
!REGALO GRATIS sólo por participar¡ Gana un premio seguro y exóticos 
viajes participando en el Rallye Wanadoo en http://www.wanadoo.es/animacion/rallye






More information about the fpc-pascal mailing list