Ant script:
And here is BAT file:
@echo off echo BAT - Before Ant run ant -f build.xml echo BAT - After Ant run
Unfortunately, when you run this BAT you get the next output:
BAT - Before Ant run
Buildfile: D:\Projects\blog\build.xml
bat-test:
[echo] Message from ANT
BUILD SUCCESSFUL
Total time: 0 seconds
So, where is the "BAT - After Ant run" echo message?
The problem is that Ant on Windows executed via ant.bat file and based on this we're calling one BAT file from another. We have to use CALL command to solve this issues, here is official note from CALL help:
Calls one batch program from another.And, here is the update BAT file:
CALL [drive:][path]filename [batch-parameters]
batch-parameters Specifies any command-line information required by the batch program.
@echo off echo BAT - Before Ant run call ant -f build.xml echo BAT - After Ant run
This comment has been removed by the author.
ReplyDeleteCould you please provide the beanshell snippet?
ReplyDeleteI deleted the some lines. Sorry Orest Ivasiv.
ReplyDeleteHere's the new one with the beanshell snippet at the end:
In my case it doesn't work.
The result of the command CALL ant -q -f C:\\...\\build.xml is:
BUILD SUCCESSFUL
Total time: 2 minutes 12 seconds
I'm running it from beanshell. Any idea? Thank's in advance!
-----------------------------------------------
beanshell snippet:
=================
bat( "CALL ant -q -f C:\\DriveAMnet\\build.xml" );
where bat is:
abreBat( )
{
g_pwBat = new PrintWriter( new FileWriter( g_strBat ) );
bat( ":\n@echo off\nsetlocal\nC:\necho. > LibVersao.log" );
}
bat( str )
{
g_pwBat.println( str );
g_pwBat.flush( );
}
fechaBat( )
{
bat( "CD " + bsh.cwd + "\\" );
g_pwBat.flush( );
g_pwBat.close( );
}
Adding just some explanation:
ReplyDeleteabreBat()= openBat()
fechaBat() = closeBat()
g_strBat = "LibVersao_" + bsh.args[0] + ".bat";
Again, thank's in advance!
bsh % exec("cmd /k call ant -f build.xml && exit");
ReplyDeleteBuildfile: D:\temp\beanshell\build.xml
bat-test:
[echo] Message from ANT
[echo]
BUILD SUCCESSFUL
Total time: 0 seconds
bsh %
The main trick is to use "cmd /k" and "exit" commands. Have a look the "cmd /?" for more details.
ReplyDeleteYou've got the point!!!
ReplyDeleteIt's working now! Thanks a lot!