I call ant command in my ruby script (on Windows XP) using %x[]. I need to change working directory so the ant starts in the right one. So there two dos commands called.
cmd = "cd #{$testing_root_directory.gsub("/","\\\\")} && ant -lib lib -f \"#{$testing_root_directory_builds.gsub("/","\\\\")}\\#{params['group']}\\#{params['run']}_build.xml\" 2>&1"
and the content of variable cmd looks like
cd C:\Program Files\TestPro\TestPro Automation Framework\ && ant -lib l
ib -f "C:\Program Files\TestPro\TestPro Automation Framework\Output Files\builds
\basics\login_build.xml" 2>&1
Which is correct and output = %x[#{cmd}] works just well.
Now I needed to add new target name when calling ant. So I changed the code to accommodate that. See the #{$target_name} at the end of the line.
cmd = "cd #{$testing_root_directory.gsub("/","\\\\")} && ant -lib lib -f \"#{$testing_root_directory_builds.gsub("/","\\\\")}\\#{params['group']}\\#{params['run']}_build.xml\" #{$target_name} 2>&1"
then puts cmd gives me correct output
cd C:\Program Files\TestPro\TestPro Automation Framework\ && ant -lib l
ib -f "C:\Program Files\TestPro\TestPro Automation Framework\Output Files\builds
\basics\login_build.xml" aftertaf 2>&1
But now output = %x[#{cmd}] never finishes. There are two targets in my ant file. I can clearly see that the first one finished (default one) and when I quit my ruby script by CTRL + C I can see that the second one (aftertaf) was about to start. There is its label one the screen.
If I use content of the second cmd variable, the one that doesn’t work from ruby, and run it directly from DOS command line it works fine. So it seems to me that ruby is not passing the string right way. cmd.inspect gives me "cd C:\\Program Files\\TestPro\\TestPro Automation Framework\\ && ant -lib lib -
f \"C:\\Program Files\\TestPro\\TestPro Automation Framework\\Output Files\\buil
ds\\basics\\login_build.xml\" aftertaf 2>&1"
I guess I can reorganize my ant targets to make my script work but I’d like to know why %x[] never finishes now.
- Apache Ant(TM) version 1.8.2 compiled on December 20 2010
- ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
- on Windows XP
UPDATE 1
My aftertaf target looks like
<target name="aftertaf" depends="taf" description="after TAF ruby stuff">
<exec executable="ruby.exe">
<arg line="C:\EduTester\others\afterant.rb update_latest 10.0.0.50:4567 basics login 20110803111432"/>
</exec>
</target>
When running cmd from system() the ant run stops at the aftertaf target. There is a aftertaf: label and that’s it.
UPDATE 2
When I press CTRL+C I get asked Terminate batch job (Y/N)? which I believe comes from ant. I added echo before and after exec in target aftertaf and the echo before exec is executed.
Using full path to ruby.exe in exec didn’t help
UPDATE 3
My ruby script is a sinatra application. I didn’t know that it matters. It looks like does matter. If I call above %X[] from ‘normal’ rb file it works. If I call it from sinatra the exec from second target is not executed. Ant batch file is waiting for something. If I remove the exec tag from the new target everything works fine. Note that the exec works if ant is run from .rb or command line or .bat file. If I run the same .rb or .bat from sinatra exec doesn’t work.
I’m just guessing here because I don’t have a Windows machine available to test at the moment, but is your command stuck waiting for some input?
I notice a couple of differences between the inspect and the puts. In the inspect version:
You could try running your command using
systeminstead of%x[]. That way, instead of being captured, ant’s output will be sent to stdout in the console and you can see what’s happening.