Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-02

How to call DOS BATCH file?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Hankovec

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

Reply by email

Aitor Santamar�a

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

Show quoted text 40 lines
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 - 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

Reply by email