Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6203833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:59:04+00:00 2026-05-24T04:59:04+00:00

I call ant command in my ruby script (on Windows XP) using %x[]. I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:59:05+00:00Added an answer on May 24, 2026 at 4:59 am

    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:

    • There’s a space between the ‘-‘ and the ‘f’ before the xml file parameter
    • The build target is different. It is ‘aftertaf’ in this case.

    You could try running your command using system instead 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’ve built a custom Maven2 plug-in using Ant. I would like to call another
I'm trying to call an Antlr task in my Ant build.xml as follows: <path
Call me a 'n00b', but I am new to creating Script Controls. I want
I need to call into a Win32 API to get a series of strings,
How do I call shell commands from inside of a Ruby program? How do
How do I call a function, using a string with the function's name? For
trying to run a simple batch file in windows 2008 task scheduler call cleanup.bat
I call function in .NET using Reflection (Method.Invoke). If an error occurs inside this
I am trying to call the following function from a static method. File directory
if i call a php file via jquery ajax, that contains a script to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.