Michal Krasny
Michal Krasny

Reputation: 5916

Windows batch - why is the if not processed?

I made a .bat file that should call Maven task and then copy newly created ear file. I don't know why the file is neither copied, nor the "file doesn't exist" message occurs. If I comment out the "mvn clean install" row, the copying is processed.

cd d:\test\
mvn clean install

if exist d:\test.war (
    echo "copying"
    copy d:\test.war D:\Development\liferay-portal-6.2-ce-ga3\deploy\
) else (
    echo "file doesn't exist"
)

Note: I know this functionality can be done by Maven plugin.

Upvotes: 0

Views: 20

Answers (1)

MC ND
MC ND

Reputation: 70923

Probably (sorry, i have no access to a maven install) the mvn command is a batch file (.bat or .cmd extension)

When a batch file directly invokes another one, the execution flow is transfered to the called one and does not return to the caller.

You need to use

call mvn clean install

now, when the called batch file ends, the execution continues in the caller.

Upvotes: 1

Related Questions