Board index » cppbuilder » Return code of bcb when started from the command line?

Return code of bcb when started from the command line?


2005-06-21 03:26:14 PM
cppbuilder64
Hi!
I'm working on a new version of my ProjectMaker tool (a tool for fast
builds with the command line compiler) and sometimes the command line
compiler fails where the IDE compiler still works. In these cases I want
to use the IDE compiler from the command line with something like:
bcb.exe /ns /m MyProject.bpr
Works fine, but the bcb return code is always 0, regardless whether the
build was successful or not.
That's in the help file:
AutoBuild. [...] This facilitates doing builds in batch mode from a
batch file. The Error Level is set to 0 for successful builds and 1 for
failed builds. [...]
Is Error Level == return code of bcb.exe?
Any hints?
Bye, Oliver
 
 

Re:Return code of bcb when started from the command line?

Oliver,
I think you are going about this the wrong way. When the command line build
fails, what is the reason? Shouldn't you be trying to find the cause of the
failure, rather than trying to work around it?
I'll save you some time here, because I know what the problem is. I've been
building my projects from the command line for many years without any
problems whatsoever. And I can tell you with 99.9% certainty that if the
command line build fails where the IDE succeeds, it is a problem with the
project file/makefile, not the command line compiler. In my opinion, this
is the result of a bug in the IDE, which I will discuss below.
My experience has shown that the IDE will search for header files in paths
that are not explicitly specified in the project file, and these are always
paths that come from loading component packages in the IDE. If your project
uses a component that happens to be loaded in the IDE, you may very well be
able to get away without adding the path to its header files in your
project, and it will probably still build successfully because the IDE will
include the path implicitly. This is, in my opinion, just plain wrong, and
should be considered a bug in the IDE.
Thus, the problem is really user error -- the user failed to add paths to
header files he is using in his project. Therefore, I would say rather than
modify your program to call the IDE to do the building (which defeats the
whole purpose of doing command line builds in the first place), let the
error propagate and fail the build. You could display a message that says,
in effect, "if your project fails to build on the command line but builds
okay from the IDE, you've probably forgotten to add required include paths
to your project."
- Dennis
"Oliver Rutsch" < XXXX@XXXXX.COM >wrote in message
Quote
Hi!

I'm working on a new version of my ProjectMaker tool (a tool for fast
builds with the command line compiler) and sometimes the command line
compiler fails where the IDE compiler still works. In these cases I want
to use the IDE compiler from the command line with something like:

bcb.exe /ns /m MyProject.bpr

Works fine, but the bcb return code is always 0, regardless whether the
build was successful or not.
That's in the help file:

AutoBuild. [...] This facilitates doing builds in batch mode from a
batch file. The Error Level is set to 0 for successful builds and 1 for
failed builds. [...]

Is Error Level == return code of bcb.exe?

Any hints?

Bye, Oliver
 

Re:Return code of bcb when started from the command line?

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote
Oliver,

I think you are going about this the wrong way. When the command line
build
fails, what is the reason? Shouldn't you be trying to find the cause of
the
failure, rather than trying to work around it?

I think Oliver just wants his tool to stop on the first file that the
compiler fails to compile, much like 'make' or batch files do.
The 'failure to compile' is 99.99% likely to be syntax errors in the files
you're trying to compile. which is why you want the build to stop there, so
you can fix your bugs and retry.
- Roddy
 

{smallsort}

Re:Return code of bcb when started from the command line?

"Roddy Pratt" <roddy at spam fritter dot com>wrote in message
Quote

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
news:42b84082$ XXXX@XXXXX.COM ...
>Oliver,
>
>I think you are going about this the wrong way. When the command line
>build
>fails, what is the reason? Shouldn't you be trying to find the cause of
>the
>failure, rather than trying to work around it?
>

I think Oliver just wants his tool to stop on the first file that the
compiler fails to compile, much like 'make' or batch files do.

One of us (you or I) has misread his post. I don't think he asking how to
stop the compile when an error occurs, but instead is complaining that the
command line compiler fails, while the IDE succeeds, and wants to know how
to interpret the IDE compiler's return value so that he can use the IDE
properly when the command line compiler fails.
Quote
The 'failure to compile' is 99.99% likely to be syntax errors in the files
Not in this case...he says the code compiles fine in the IDE, so the code
itself is fine. I have been doing this for many years, and I am willing to
bet the problem is the project file. Therefore, I submit that he is trying
to solve the wrong problem...or rather, trying to solve a problem that is
not his responsibility to fix.
When Oliver responds, we'll know more...
- Dennis
 

Re:Return code of bcb when started from the command line?

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote
One of us (you or I) has misread his post. I don't think he asking how to
stop the compile when an error occurs, but instead is complaining that the
command line compiler fails, while the IDE succeeds, and wants to know how
to interpret the IDE compiler's return value so that he can use the IDE
properly when the command line compiler fails.
Mea culpa. I skimmed the post, and added some mental baggage from my
Projectmaker wishlist....
- Roddy
 

Re:Return code of bcb when started from the command line?

"Roddy Pratt" <roddy at spam fritter dot com>wrote in message
Quote
"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>One of us (you or I) has misread his post. I don't think he asking how
to
>stop the compile when an error occurs, but instead is complaining that
the
>command line compiler fails, while the IDE succeeds, and wants to know
how
>to interpret the IDE compiler's return value so that he can use the IDE
>properly when the command line compiler fails.

Mea culpa. I skimmed the post, and added some mental baggage from my
Projectmaker wishlist....
No problem...that's understandable.
- Dennis
 

Re:Return code of bcb when started from the command line?

Hi Dennis,
Quote


One of us (you or I) has misread his post. I don't think he asking how to
stop the compile when an error occurs, but instead is complaining that the
command line compiler fails, while the IDE succeeds, and wants to know how
to interpret the IDE compiler's return value so that he can use the IDE
properly when the command line compiler fails.

That's exactly what I want. But I mean projects where the command line
compiler dies with an internal compiler error and the IDE does not. So I
don't mean 'normal' compiler errors, as you suggested in your first
post, but real bugs in the command line compiler (I think an internal
compiler or linker error is always a bug). Or can it be that an internal
compiler error in the command line compiler is caused by missing include
pathes?
I tried so many things to get it work with the command line compiler
without success. We have here 2 of 50 projects where I have to use the
IDE and I want to automate this step.
Quote

Not in this case...he says the code compiles fine in the IDE, so the code
itself is fine. I have been doing this for many years, and I am willing to
bet the problem is the project file. Therefore, I submit that he is trying
to solve the wrong problem...or rather, trying to solve a problem that is
not his responsibility to fix.
Yes, I think the code of the problematic projects is O.K. as it runs and
compiles fine in the IDE. But I see no hope when it comes to internal
compiler errors. Sometimes reordering or splitting of source files helps
but in general I don't think than I get my two projects work with the
command line compiler. And in these rare cases I think it's O.K. to
compile it with the IDE.
Thanks for your attention and btw.: Any clue to the return code of bcb.exe?
Bye, Oliver
 

Re:Return code of bcb when started from the command line?

"Oliver Rutsch" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Dennis,
>
>
>One of us (you or I) has misread his post. I don't think he asking how
to
>stop the compile when an error occurs, but instead is complaining that
the
>command line compiler fails, while the IDE succeeds, and wants to know
how
>to interpret the IDE compiler's return value so that he can use the IDE
>properly when the command line compiler fails.
>

That's exactly what I want. But I mean projects where the command line
compiler dies with an internal compiler error and the IDE does not. So I
don't mean 'normal' compiler errors, as you suggested in your first
post, but real bugs in the command line compiler (I think an internal
compiler or linker error is always a bug). Or can it be that an internal
compiler error in the command line compiler is caused by missing include
pathes?
I tried so many things to get it work with the command line compiler
without success. We have here 2 of 50 projects where I have to use the
IDE and I want to automate this step.
>
>Not in this case...he says the code compiles fine in the IDE, so the
code
>itself is fine. I have been doing this for many years, and I am willing
to
>bet the problem is the project file. Therefore, I submit that he is
trying
>to solve the wrong problem...or rather, trying to solve a problem that
is
>not his responsibility to fix.

Yes, I think the code of the problematic projects is O.K. as it runs and
compiles fine in the IDE. But I see no hope when it comes to internal
compiler errors. Sometimes reordering or splitting of source files helps
but in general I don't think than I get my two projects work with the
command line compiler. And in these rare cases I think it's O.K. to
compile it with the IDE.

Thanks for your attention and btw.: Any clue to the return code of
bcb.exe?
Ok, this is definitely a different situation than I interpreted from your
original post. I have seen similar problems with the command-line compiler,
but I've only seen them in BCB6, never BCB5. The only case I can think of
is where there is code like this:
int RowCount = StringGrid1->RowCount;
StringGrid1->RowCount = ++RowCount;
This code, for some odd reason, compiles fine in the BCB6 IDE, but won't
compile on the command line. So the problem in this case was corrected by
changing the code itself to work around the bug (separating the increment
from the assignment):
int RowCount = StringGrid1->RowCount;
++RowCount;
StringGrid1->RowCount = RowCount;
...which then compiles fine in both the IDE and on the command line.
Sorry, I don't know why the IDE is not returning the correct error code.
How are you checking it? Can you show your code?
- Dennis
 

Re:Return code of bcb when started from the command line?

"Oliver Rutsch" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Dennis,
Thanks for your attention and btw.: Any clue to the return code of
bcb.exe?
Oliver,
I just created a little batch file (testide.bat):
@echo off
bcb.exe /ns /m myproject.bpr
echo errorlevel is %errorlevel%
if %errorlevel% == 0 (
echo Build Okay
) else (
echo Build Failed
)
I tested this batch file on BCB5 and BCB6, and it produces the expected
results for both successful and failed builds. The IDE's are definitely
returning the correct values, so if you are having trouble, you are doing
something wrong (maybe looking at the wrong value?).
How are you invoking the IDE? Please show your code.
- Dennis
 

Re:Return code of bcb when started from the command line?

Hi Dennis,
Quote
>Thanks for your attention and btw.: Any clue to the return code of

bcb.exe?

Oliver,

I just created a little batch file (testide.bat):

@echo off
bcb.exe /ns /m myproject.bpr
echo errorlevel is %errorlevel%
if %errorlevel% == 0 (
echo Build Okay
) else (
echo Build Failed
)

I tested this batch file on BCB5 and BCB6, and it produces the expected
results for both successful and failed builds. The IDE's are definitely
returning the correct values, so if you are having trouble, you are doing
something wrong (maybe looking at the wrong value?).
I tested this batch file and it isn't working on my computer. If the
make (for the command line compiler!) command fails, it returns the
correct errorlevel (1), if the IDE fails it returns always 0. Strange,
isn't it?
I tested this in the command shell on some other machines with two commands:
bcb.exe /ns /m MyProject.bpr
echo %errorlevel%
Unfortunately the errorlevel is always 0. I don't think that there's
anything special on our BCB5(SP1) installations. Are you really sure
that BCB5 sets the correct errorlevel?
All other commands are working as expected. In my program I use
GetExitCodeProcess, but if even the batch file fails to get the correct
return code then I think it's no wonder, that my program gets the wrong
error level, too.
Thanks for your suggestions!
Bye, Oliver
 

Re:Return code of bcb when started from the command line?

"Oliver Rutsch" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Dennis,

I tested this batch file and it isn't working on my computer. If the
make (for the command line compiler!) command fails, it returns the
correct errorlevel (1), if the IDE fails it returns always 0. Strange,
isn't it?
I tested this in the command shell on some other machines with two
commands:

bcb.exe /ns /m MyProject.bpr
echo %errorlevel%

Unfortunately the errorlevel is always 0. I don't think that there's
anything special on our BCB5(SP1) installations. Are you really sure
that BCB5 sets the correct errorlevel?
Of course I'm sure! I tested it with a good project that successfully
compiles and it printed, "Build Okay." Then I modified a single file so
that a compiler error would be generated and it failed as expected and
printed, "Build Failed." I did this with both BCB5 and BCB6, and they both
responded as expected. Here is a text-capture of my exact results as
executed just moments ago:
P:\G2-Setup>testide
errorlevel is 0
Build Okay
P:\G2-Setup>testide
errorlevel is 1
Build Failed
Quote
All other commands are working as expected. In my program I use
GetExitCodeProcess, but if even the batch file fails to get the correct
return code then I think it's no wonder, that my program gets the wrong
error level, too.
Then I don't know what to tell you. Something is definitely goofy. But
since BCB is definitely returning a '1' for failure, I have to think it is
something on your system. Another thing you could try is create a little
EXE that does nothing but return a 1:
int main( int argc, char *argv[] )
{
return 1;
}
Then call this executable from a batch file to test %errorlevel% and then
call it from your program to test GetExitCodeProcess(). Both should get a
1. If they do, then BCB is acting weird for some reason. If they don't,
then there is a problem with your system (although I'm having a very hard
time thinking of anything that could cause this).
- Dennis
 

Re:Return code of bcb when started from the command line?

Hi Dennis,
Quote

Of course I'm sure! I tested it with a good project that successfully
compiles and it printed, "Build Okay." Then I modified a single file so
that a compiler error would be generated and it failed as expected and
printed, "Build Failed." I did this with both BCB5 and BCB6, and they both
responded as expected. Here is a text-capture of my exact results as
executed just moments ago:
Please don't get me wrong. Of course I'm trusting you. But sometimes
it's better to ask twice, especially when I have no more ideas ;-)
Quote

Then I don't know what to tell you. Something is definitely goofy. But
since BCB is definitely returning a '1' for failure, I have to think it is
something on your system.
I tested four systems with Win2000 and XP and all the machines gave me
the same result: return code is always 0, although the project failed to
compile.
Quote
Another thing you could try is create a little
EXE that does nothing but return a 1:

int main( int argc, char *argv[] )
{
return 1;
}

Then call this executable from a batch file to test %errorlevel% and then
call it from your program to test GetExitCodeProcess(). Both should get a
1.
Yes, this works fine on every machine. As I told before, the make
command behaves perfectly fine and gives always the correct result.
If they do, then BCB is acting weird for some reason. If they don't,
Quote
then there is a problem with your system (although I'm having a very hard
time thinking of anything that could cause this).
Very strange, indeed. It failed to work on four systems. I suggest
you're using XP/2000, too?
Thanks for your time and bye,
Oliver
 

Re:Return code of bcb when started from the command line?

"Oliver Rutsch" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Dennis,
>

Please don't get me wrong. Of course I'm trusting you. But sometimes
it's better to ask twice, especially when I have no more ideas ;-)
I understand.
Quote
I tested four systems with Win2000 and XP and all the machines gave me
the same result: return code is always 0, although the project failed to
compile.
Maybe there is a special error case where BCB does not return the correct
error code. What error is it? Is it something that I could re-create as a
test?
Also, I thought you only wanted to use the IDE when the command line
compiler fails but the IDE doesn't? It sounds like you are trying to use
the IDE all the time now.
Quote
Very strange, indeed. It failed to work on four systems. I suggest
you're using XP/2000, too?
Yes, I am using XP.
- Dennis
 

Re:Return code of bcb when started from the command line?

Hi again,
Quote

Maybe there is a special error case where BCB does not return the correct
error code. What error is it? Is it something that I could re-create as a
test?
I tried to compile a fairly simple project. Just made a project with
File->New Application and put some rubbish into the constructor. IDE
fails but return code is 0 ;-(
Quote

Also, I thought you only wanted to use the IDE when the command line
compiler fails but the IDE doesn't? It sounds like you are trying to use
the IDE all the time now.
No no no. Then the whole tool wouldn't make sense anymore. But it would
have been nice if I got the return code even for my few projects who
don't want to compile with the command line compiler.
Maybe I should use some kind of workaround. If the IDE fails to compile,
it writes an error log. If everything's fine it does not. But maybe this
fails if there are only a few warnings but the project compiles O.K.
Thanks for your time,
Oliver
 

Re:Return code of bcb when started from the command line?

"Oliver Rutsch" < XXXX@XXXXX.COM >wrote in message
Quote
Hi again,

>
>Maybe there is a special error case where BCB does not return the
correct
>error code. What error is it? Is it something that I could re-create
as a
>test?

I tried to compile a fairly simple project. Just made a project with
File->New Application and put some rubbish into the constructor. IDE
fails but return code is 0 ;-(
Well then, I'm all out of ideas. It works just fine for me, and I have the
same compiler, the same OS, and you have the script I wrote, so there must
be something else that is different that you are either not sharing or have
missed or forgotten.
Quote
But maybe this
fails if there are only a few warnings but the project compiles O.K.
I don't understand...what are you trying to say here?
- Dennis