Solved

execution of clearcase' cleartool shell from java code

Posted on 2003-10-28
11
423 Views
Last Modified: 2010-05-18
execution of clearcase' cleartool shell from java code does not work
0
Comment
Question by:gmeltsin
  • 6
  • 4
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9640610
Try it using this:


import java.io.*;

public class RunAsync {

    public static void main(String args[]) {

     try {

        if(args.length < 1) {
          System.out.println("Usage: java RunAsync <command string>");
          System.exit(-1);
        }
        Process pro = null;
        if (args.length > 1) {
          pro = Runtime.getRuntime().exec(args);
        }
        else {
          pro = Runtime.getRuntime().exec(args[0]);
        }
        InputStream error = pro.getErrorStream();
        InputStream output = pro.getInputStream();
        Thread err = new Thread(new OutErrReader(error));
        Thread out = new Thread(new OutErrReader(output));
        out.start();
        err.start();
        pro.waitFor();
     }
     catch(java.io.IOException e) {
       e.printStackTrace();
     }
     catch(java.lang.InterruptedException e) {
       e.printStackTrace();
     }

    }

    static class OutErrReader implements Runnable {
      InputStream is;

      public OutErrReader(InputStream is) {
        this.is = is;
      }

      public void run() {
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(is));
          String temp = null;
          while((temp = in.readLine()) != null) {
             System.out.println(temp);
          }
          is.close();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
}
0
 

Author Comment

by:gmeltsin
ID: 9642463
clearcase's cleartool expects clearcase view to be set prior to using basic functions(checking ,checkout, etc).
so i need to execute two commands
1. Runtime.getRuntime().exec("cleartool setview view_name");  - sets the view
2. Runtime.getRuntime().exec("cleartool co file_name"); - checksout the file

The problem is that second process does not recognize what was done in first
Second process does not 'see' that the view was set
thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9642535
I don't see how this could be any different to how it's executed at the command line.

Are you sure the first is succeeding? You can always change

>>pro.waitFor();

to

System.out.println("Process return value: " + pro.waitFor());

to see
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:gmeltsin
ID: 9642753
no return value
pro.waitFor() hangs after Runtime.getRuntime().exec("cleartool setview view_name"),
but the same command is fine from command line
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9644779
>>pro.waitFor() hangs ...

and are you fully using the code i posted?
0
 

Author Comment

by:gmeltsin
ID: 9650797
when i am using threads the app stops working when i create them.
probably because it's inside struts.
without threads it hangs at pro.waitFor() level
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9651596
>>the app stops working when i create them

What do you mean by that? Don't see it should be a Struts-related problem. Maybe your container...
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 9651604
Of course it's conceivable that your container's security policy disallows the creating of processes.
0
 

Author Comment

by:gmeltsin
ID: 9652016
but i am able  to run other processes...
it seems that the problem is clearcase's cleartool command. it takes the process to the different shell and never exists from there. That's why the app hangs
Anyway, thanks for help. the points are rightfully yours
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9652045
>>it takes the process to the different shell and never exists from there.

Well I don't know what you mean by the above, but thanks anyway.
0
 
LVL 3

Expert Comment

by:Reddgum
ID: 10179780


"Runtime.getRuntime().exec("cleartool setview view_name");  - sets the view"

The CT setview command only works in Unix, and from what I can tell from your code, each incantation of Runtime.getRuntime().exec actually either runs a new shell or a new thread. If you are attempting to run this code from a Windows platform, "setview" will fail.

Also,

"Runtime.getRuntime().exec("cleartool co file_name"); - checksout the file"

Sure, but then the process will definitely hang WAITING FOR USER INPUT, as you left out the
-nc flag so that the process would not ask for comments for the check-in. :-)

-Just strolling by amusing myself with a little reading.

Cheers,
         -Mike




0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 65
tomcat not starting 6 69
eclipse buid path vs tomcat lib path 10 34
Java: The Public Class Main 4 32
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question