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 258809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:12:41+00:00 2026-05-11T22:12:41+00:00

I am trying to call cleartool from an java application, but cleartool hangs even

  • 0

I am trying to call cleartool from an java application, but cleartool hangs even for a simple “-version” argument. Running cleardiff instead of cleartool works fine, so apparently there is something specific with the cleartool program (which I assume is related to its interactive capabilities).

The following program

import java.io.*;
import java.util.*;

public class ExecTesting extends Thread {

    private List<String> command = new ArrayList<String>();

    public ExecTesting (List<String> command) {
        super();
        this.command = command;
    }

    private void print(String s) {
        System.out.println(s);
    }

    @Override
    public void run() {
        Process process;
        OutputStream stdin;
        InputStream stdout;
        InputStream stderr;
        String line;

        try {
            String commandString = joinList(command, " ");
            print("Executing: " + commandString);

            // runtime.exec has several issues (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1)
            // better to use ProcessBuilder (http://java.sun.com/developer/JDCTechTips/2005/tt0727.html#2)
            //process = Runtime.getRuntime().exec(commandString);
            process = new ProcessBuilder(command).start();
            // it fails in both cases though

            stdin  = process.getOutputStream();
            stdout = process.getInputStream();
            stderr = process.getErrorStream();

            BufferedReader bufferedStderr = new BufferedReader(new InputStreamReader(stderr));
            while ((line = bufferedStderr.readLine()) != null) {
                print("stderr: " + line);
            }
            bufferedStderr.close();

            BufferedReader bufferedStdout = new BufferedReader(new InputStreamReader(stdout));
            while ((line = bufferedStdout.readLine()) != null) {
                print("stdout: " + line);
            }
            bufferedStdout.close();

            stdin.close();
            stdout.close();
            stderr.close();

            process.waitFor();
            print("Execution finished, exit code " + process.exitValue());
            process.destroy();
        } catch (IOException e) {
            print("IOException: " +e.getStackTrace());
        } catch (InterruptedException e) {
            print("InterruptedException: " + e.getStackTrace());
        }

    }

    /* assumes a list with at least one element */
    private static String joinList(List<String> list, String glue) {
        Iterator<String> i = list.iterator();
        String ret = i.next();
        while (i.hasNext()) {
            ret += glue + i.next();
        }
        return ret;
    }

    public static void main(String[] args) {
        ArrayList<String> cmd1 = new ArrayList<String>();
        cmd1.add("c:\\Program Files\\Rational\\ClearCase\\bin\\cleardiff.exe");
        cmd1.add("-version");
        ExecTesting et1 = new ExecTesting(cmd1);
        et1.start();

        ArrayList<String> cmd2 = new ArrayList<String>();
        //cmd2.add("c:\\Program Files\\Rational\\ClearCase\\bin\\cleardiff.exe");
        cmd2.add("c:\\Program Files\\Rational\\ClearCase\\bin\\cleartool.exe");
        cmd2.add("-version");
        ExecTesting et2 = new ExecTesting(cmd2);
        et2.start();

        et1 = new ExecTesting(cmd1);
        et1.start();
    }
}

gives the following output

Executing: [c:\Program Files\Rational\ClearCase\bin\cleardiff.exe, -version]
Executing: [c:\Program Files\Rational\ClearCase\bin\cleartool.exe, -version]
Executing: [c:\Program Files\Rational\ClearCase\bin\cleardiff.exe, -version]
stdout: cleardiff                         2003.06.10+ (Tue Jul 13 14:02:05  2004)
Execution finished, exit code 0

hanging on the execution of the cleartool command. If instead cmd2 is changed to cleardiff the output is as expected

Executing: [c:\Program Files\Rational\ClearCase\bin\cleardiff.exe, -version]
Executing: [c:\Program Files\Rational\ClearCase\bin\cleardiff.exe, -version]
Executing: [c:\Program Files\Rational\ClearCase\bin\cleardiff.exe, -version]
stdout: cleardiff                         2003.06.10+ (Tue Jul 13 14:02:05  2004)
Execution finished, exit code 0
stdout: cleardiff                         2003.06.10+ (Tue Jul 13 14:02:05  2004)
Execution finished, exit code 0
stdout: cleardiff                         2003.06.10+ (Tue Jul 13 14:02:05  2004)
Execution finished, exit code 0

Question: Does anyone know why cleartool is hanging and how to fix?

  • 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-11T22:12:41+00:00Added an answer on May 11, 2026 at 10:12 pm

    You should consume the stdout and stderr in separate threads, otherwise you will experience blocking behaviour.

    I suspect that’s what’s happening in this instance (and that it’s unrelated to cleartool/cleardiff other than they’re outputting stdout/err). See this answer for more information.

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I am trying to call a shell script that sets a bunch of environment
I am trying to call a webservice using ssl. How do i get the
I am trying to call out to a legacy dll compiled from FORTRAN code.
I am trying to call a setTimeout from within a setInterval callback: function callback()

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.