Frage

I am trying to run two cmd files from the post-build event of a Delphi 2007 project.

The build events are configured like this:

..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)
..\copydlls.cmd $(OUTPUTDIR)

The first one works fine, the second one seems to never get called at all.

If I change the order like this:

..\copydlls.cmd $(OUTPUTDIR)
..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)

Again, only the first one is executed.

Is this a known limitation / bug of Delphi 2007 or am I doing something wrong here? (I could have sworn that this used to work in the past.)

EDIT: I found a workaround:

%comspec% /c ..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)
%comspec% /c ..\copydlls.cmd $(OUTPUTDIR)

This works as expected. Still odd.

EDIT2: There is another option, I found in this answer on StackOverflow:

call ..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)
call ..\copydlls.cmd $(OUTPUTDIR)

I guess (without having tried it), that is is a problem only if the build event is a cmd file and the past experience I cited above did not call cmd files but executables.

War es hilfreich?

Lösung

I guess the workaround I added in EDIT2 is the one that should be used, so I am adding this as an answer myself:

When calling cmd files (probably also bat files) a "call" must be added in front of it:

call ..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)
call ..\copydlls.cmd $(OUTPUTDIR)

Andere Tipps

The problem you face can be understood from the documentation for the call command.

Call

Calls one batch program from another without stopping the parent batch program.

In other words, if you omit call when executing a sub-program, then the parent batch program is stopped when the sub-program returns.

So, you must use call to execute sub-programs in your build actions.

Update

I did not mention this first time round, but implicit in the above is that the build actions are executed by the command interpreter, cmd.exe.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top