Board index » delphi » Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)

Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)

I'vfe created a pascal program which tests if further files exist or not on a
PC.
If a file tested doesn't exist, the program displays on the screen the error
(which file doesn't exist), and stops immediately.
It works fine while i call the executable program directly from dos.
But i've to call this program on a batch file.
I call my executable program with   Call c:\xxx\myprog.exe
It works fine while no errors occurs.
But when an error occurs, the program pascal displays the error, breaks, and
the batch file continue as if no errors where detected.
If i call my pascal program without using the 'call' instruction in the batch
file, the program works fine but stops immediately after, even if no error
occur.
So my question is very simple :
Is it possible to send from my pascal program to the batch file, when an error
occurs,  a code error (e.g.  errorlevel, or something else), which can be
understood by the batch file to test if an error has occured during the
execution of the program pascal and then break the batch.???
If yes, how can i do ?
(I use Turbo Pascal 5)
Thank you for all who help me to resolve this problem.

David.

e-mail: excoff...@lyon.cemagref.fr

P.S.: sorry for my disgraceful english...

 

Re:Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)


Hello,
Quote
>I'vfe created a pascal program which tests if further files exist or not on a
>PC.
>If a file tested doesn't exist, the program displays on the screen the error
>(which file doesn't exist), and stops immediately.
>It works fine while i call the executable program directly from dos.
>But i've to call this program on a batch file.
>I call my executable program with   Call c:\xxx\myprog.exe
>It works fine while no errors occurs.
>But when an error occurs, the program pascal displays the error, breaks, and
>the batch file continue as if no errors where detected.
>If i call my pascal program without using the 'call' instruction in the batch
>file, the program works fine but stops immediately after, even if no error
>occur.
>So my question is very simple :
>Is it possible to send from my pascal program to the batch file, when an error
>occurs,  a code error (e.g.  errorlevel, or something else), which can be
>understood by the batch file to test if an error has occured during the
>execution of the program pascal and then break the batch.???
>If yes, how can i do ?
>(I use Turbo Pascal 5)

You'd better not use the 'call .exe', just execute it. In your pascal program you can use
the command 'halt' it will stop your program, but you can also give an errorlevel with it.
For example halt(1) will generate errorlevel 1 which can be detected by your batch file.

Hope this was any help....
greetz -frank korpershoek-

Re:Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)


Quote
excoff...@lyon.cemagref.fr (David Excoffier) wrote:

> I'vfe created a pascal program which tests if further files exist or not on a
> PC.
> If a file tested doesn't exist, the program displays on the screen the error
> (which file doesn't exist), and stops immediately.
> It works fine while i call the executable program directly from dos.
> But i've to call this program on a batch file.
> I call my executable program with   Call c:\xxx\myprog.exe
> It works fine while no errors occurs.
> But when an error occurs, the program pascal displays the error, breaks, and
> the batch file continue as if no errors where detected.
> If i call my pascal program without using the 'call' instruction in the batch
> file, the program works fine but stops immediately after, even if no error
> occur.
> So my question is very simple :
> Is it possible to send from my pascal program to the batch file, when an error
> occurs,  a code error (e.g.  errorlevel, or something else), which can be
> understood by the batch file to test if an error has occured during the
> execution of the program pascal and then break the batch.???
> If yes, how can i do ?
> (I use Turbo Pascal 5)
> Thank you for all who help me to resolve this problem.

> David.

I'm not really good at batch programming but you could try
the following:

 In your pascal program, when you quit with an error, use
 Halt(1);  This will set DOS errorlevel to 1.

 In your batch file, use

  ...

  x:\path\yourprog.exe
  IF ERRORLEVEL==1 GOTO End

  ...

  :END

Hope that helps somewhat.  Mike

Re:Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)


Quote
excoff...@lyon.cemagref.fr (David Excoffier) wrote:
>So my question is very simple :
>Is it possible to send from my pascal program to the batch file, when an error
>occurs,  a code error (e.g.  errorlevel, or something else), which can be
>understood by the batch file to test if an error has occured during the
>execution of the program pascal and then break the batch.???
>If yes, how can i do ?
>(I use Turbo Pascal 5)
>Thank you for all who help me to resolve this problem.

If, as I assume, the function you are using to stop the program is Halt, you can specify an errorlevel
as a parameter to the procedure. For example, if you wanted an errorlevel of 1, you could specify:

Halt(1);

which would terminate the program immediately and put a value of 1 into AX (which is what DOS
checks with the command "if errorlevel". See the help on Halt for more info.

At any rate, your program should not be stopping execution of a batch file, whether you use "call"
to execute it or not. I don't know the particulars of your program, but I can't remember seeing a TP
program stop a batch file like that. Maybe someone else with experience in that area can help?

Alan

Re:Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)


Quote
David Excoffier (excoff...@lyon.cemagref.fr) wrote:
> I call my executable program with   Call c:\xxx\myprog.exe

The CALL instruction is only useful for BATches calling other BATches and
wnating return to the original BATch.

In your program, report errors with Halt(1) as already explained and in your
batch :
EXIST C:\Path\MyFile.DAT
if "ErrorLevel"=="1" Goto TheEnd
Echo File exists
Pause
:TheEnd

You could also use 4DOS that implements directly %@Exist[FileName]

Quote
> P.S.: sorry for my disgraceful english...

C'est vrai, pourquoi faire simple quand on peut faire compliqu ? ;-)
--
Jean-Christophe Boggio                          c...@gestalt.freenix.fr
Pascal and Linux {*word*60}, Dos and Windows independant programmer.

Re:Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)


Quote
excoff...@lyon.cemagref.fr (David Excoffier) writes:
>I'vfe created a pascal program which tests if further files exist or not on a
>PC.
[...]
>Thank you for all who help me to resolve this problem.
>David.
>e-mail: excoff...@lyon.cemagref.fr
>P.S.: sorry for my disgraceful english...

If you test it in batch files, you don't need such a program.

Just do it like this:

REM EXAMPLE.BAT
IF EXIST TESTED.FIL GOTO ItExists
ECHO TESTED.FIL doesn't exist!
GOTO TheEnd
:ItExists
type TESTED.FIL
:TheEnd

Hope this helps.
Ch. Eltschka
If you are missing information, just remember, that this article was moving
through the net with high relativistic speed, so any shortening comes from lorentz
contraction...

Re:Heeelp! Pb with .BAT file calling an EXE file (created with Pascal)


Quote
David Excoffier (excoff...@lyon.cemagref.fr) wrote:

: I'vfe created a pascal program which tests if further files exist or not on a
: PC.
: If a file tested doesn't exist, the program displays on the screen the error
: (which file doesn't exist), and stops immediately.
: It works fine while i call the executable program directly from dos.
: But i've to call this program on a batch file.
: I call my executable program with   Call c:\xxx\myprog.exe
: It works fine while no errors occurs.
: But when an error occurs, the program pascal displays the error, breaks, and
: the batch file continue as if no errors where detected.
: If i call my pascal program without using the 'call' instruction in the batch
: file, the program works fine but stops immediately after, even if no error
: occur.
: So my question is very simple :
: Is it possible to send from my pascal program to the batch file, when an error
: occurs,  a code error (e.g.  errorlevel, or something else), which can be
: understood by the batch file to test if an error has occured during the
: execution of the program pascal and then break the batch.???
: If yes, how can i do ?
: (I use Turbo Pascal 5)
: Thank you for all who help me to resolve this problem.

: David.

: e-mail: excoff...@lyon.cemagref.fr

: P.S.: sorry for my disgraceful english...
Mine is worth.

When an executable breaks, the batch doesn't break, no matter what th error
code is.

Try this:

your prog;
if so and so then
  Halt(0)
else
  begin
    report error
    Halt(1);
  end;

in your batch

MyProg
if errorlevel 1 goto exit
.
.
.
:exit

Other Threads