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

  • SEARCH
  • Home
  • 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 6802769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:15:47+00:00 2026-05-26T19:15:47+00:00

I have a script which detects OS using Catalina.bat for windows and Catalina.sh for

  • 0

I have a script which detects OS using Catalina.bat for windows and Catalina.sh for UNIX..it executes successfully for UNIX but for windows its not able to extract OS version from Catalina.bat..the reason i find out is because in Catalina.bat when it executes this line

if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

then OS version statement is not reached in catalina.bat file,so the solution to this is i guess; explicitly set CATALINA_HOME environment variable using my Ant script itself; how to do that plz suggest any solution.

i was using this code, here OS.version property should have cached the OS version from catalina.bat file similar code in UNIX is working fine but win i wonder whats wrong

<property name="version" location="${My_proj}\tomcat\bin\catalina.bat"/>
<exec executable="${version}" outputproperty="OS.version">
        <arg value="version" />
          <redirector>
            <outputfilterchain>
               <tokenfilter>
                <containsstring contains="OS Name:"/>
                 <replacestring from="OS Name:        " to=""/> 
                </tokenfilter>
            </outputfilterchain>
         </redirector>


  </exec>

PROBLEM O SOLVED: you were right ..

<exec executable="cmd" outputproperty="tomcat.version">
      <arg value="/c"/>
      <arg value="${MY_PROJ}\tomcat\bin\version.bat"/>
      <env key="CATALINA_HOME" value="${MY_PROJ}\tomcat\"/>

        <redirector>
        <outputfilterchain>
          <tokenfilter>
            <containsstring contains="Server version"/> 
            <replaceregex pattern="Server version: Apache Tomcat/(.*)$" replace="\1"/>
          </tokenfilter>
        </outputfilterchain>
      </redirector>

    </exec>
    <echo message="tomcat.version: ${tomcat.version}"/>

OUTPUT:

versioncat:
     [echo] tomcat.version: 6.0.33

LAST BUL NOT THE LEAST CAN ANY1 ANSWER OR SUGGEST A WORKAROUND FOR MY LAST COMMENT QUERY THE SILLY QUESTION

  • 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-26T19:15:47+00:00Added an answer on May 26, 2026 at 7:15 pm

    If I understand correctly, you are executing this OS detection from Ant. In that case, can you not instead use Ant’s built-in support for OS identification – in the os condition?

    However, if you really need to execute catalina.bat while setting CATALINA_HOME, you could do so using a nested env element in you exec task.

    Here is a sample build file which uses both approaches:

    <project default="test">
    
      <target name="test">
    
        <!-- Execute a command, in this case a simple bat file
             which echoes the value of the var set in the env block 
        -->
        <exec executable="cmd">
          <arg value="/c"/>
          <arg value="test.bat"/>
          <env key="CATALINA_HOME" value="whatever"/>
        </exec>
    
        <!-- echo the values of built-in OS related properties -->
        <echo message="os.arch: ${os.arch}"/>
        <echo message="os.name: ${os.name}"/>
        <echo message="os.version: ${os.version}"/>
    
        <!-- test one of the os conditions -->
        <condition property="is.windows">
          <os family="windows"/>
        </condition>
        <echo message="is.windows ? ${is.windows}"/>
    
      </target>
    
    </project>
    

    Here is the content of test.bat:

    echo CATALINA_HOME=%CATALINA_HOME%
    

    Here is the output:

    test:
         [exec]
         [exec] C:\tmp\ant>echo CATALINA_HOME=whatever
         [exec] CATALINA_HOME=whatever
         [echo] os.arch: x86
         [echo] os.name: Windows XP
         [echo] os.version: 6.1 build 7601 Service Pack 1
         [echo] is.windows ? true
    

    Regarding your subsequent question (in comments) about tomcat version…

    I now guess you are executing this version detection via Ant in your runtime environment.

    Ant and Java don’t know about your Tomcat environment, so now you’re back to executing %CATALINA_HOME%\bin\catalina.bat -version and parsing what you need from the output.

    Here’s a working example:

    <project default="version">
      <property environment="env"/>
    
      <condition property="script.ext" value="bat">
        <os family="windows"/>
      </condition>
      <condition property="script.ext" value="sh">
        <os family="unix"/>
      </condition>
    
      <target name="version">
        <exec executable="${env.CATALINA_HOME}/bin/version.${script.ext}" outputproperty="tomcat.version">
          <redirector>
            <outputfilterchain>
              <tokenfilter>
                <containsstring contains="Server version"/> 
                <replaceregex pattern="Server version: Apache Tomcat/(.*)$" replace="\1"/>
              </tokenfilter>
            </outputfilterchain>
          </redirector>
        </exec>
        <echo message="tomcat.version: ${tomcat.version}"/>
      </target>
    </project>
    

    And here is the output:

    version:
         [echo] tomcat.version: 5.5.33
    

    Note that this example assumes that you have the CATALINA_HOME (and JAVA_HOME) environment variable set in your terminal.

    Alternatively, you could pass these variables using a nested <env> element as previously discussed. But it seems more likely that these should come from the runtime environment rather than embedded in your build file.

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

Sidebar

Related Questions

I have a Greasemonkey script which uses jQuery and detects if a class is
If I have a script which will send sms every minute using crontab :
I have a script which contacts a few sources and tell them the IP-address
I have a script which logs on to a remote server and tries to
I have a script which will be run interactively by non-technical users. The script
I have this script which basically toggles a bgColor class on and off so
I have a script which hides (display:none) certain divs in the list on page
I have a script which creates a user-defined object like this: obj = new
I have a script which, each time is called, gets the first line of
I have a script which tracks visits & referers to a website. I send

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.