Cuttin a string in bash

Hi,
I want to cut a string in bash to remove a number in the string, and save that number for further formatting.
At the moment, I am doing it with two double sed's, but I was wondering if it is possible to do it more elegantly.
Here's an example of what I want to do.
Given the String=Agora1.gif
I want to get the the number 1 out of the string.
So, what I am doing is
Number=`echo $String | sed "s/Agora//" | sed "s/\.gif//"`
That will save the number. I can later change the name;
NewName=`printf "Agora%02i" $Number`
and use the new name to rename the original file
mv $String $NewName
I want to do this for a bath of photographs. So far, it works, but I feel that it could be improved.

Also note that
NewName=`printf "Agora%02i" $Number`
can be written as:
printf -v NewName "Agora%02i" $Number
This will assign the output of printf to the variable NewName.

Similar Messages

  • Construction of command strings in bash or python? [Solved]

    I am trying to figure a way to construst a command in bash [or python]
    syntax is
    command 'function string'
    problem being the bit inside single quotes? I want to use different strings leaving the rest of command structure as is
    something like
    command 'function ' + string
    the function and string must be within single quotes
    there must be a way round maybe its easier in python not sure??
    MrG
    Last edited by Mr Green (2008-02-08 06:49:10)

    Gilneas:  I really don't think anything of offense was meant in that post.  In fact I'm not to sure where you could have got offended (the comment about going to use python after your help in bash?).  My reading of this was that Mr Green was thankful for your help.
    Anyway, something obviously annoyed you enough to come back four hours later and repost here.  In fact, your second post is probably going beyond what is acceptable here.  If someone offends you or is abusive, etc, then you should use the "Report" link to contact a forum moderator about it, not retaliate with a similarly offensive post.
    Last edited by Allan (2008-02-08 06:24:41)

  • Check a string in bash for unwanted characters

    Hello,
    I'm trying to do a bash script that checks a variable against a list of unwanted characters, e.g. to parse a file name.
    This doesn't really sound like a difficult task, but for some reason, whatever I've tried so far does not work, including my last attempt, shown below. Perhaps I'm doing something silly here - and I'm getting tired of it. What would be the best way for instance to parse a file name for invalid characters, or to accomplish or fix the below?
    #!/bin/bash
    read -p "Enter a filename: " fname
    invalid_chars=", . ! @ # \$ % ^ & \* ( ) + = ? { } [ ] | ~"
    i=0
    while (( i <= ${#fname} )); do
       char=${fname:$i:1}
       for char in `echo $invalid_chars`; do
         echo "$char"
       done
       (( i += 1 ))
    doneThanks.

    Meanwhile I figured out the mistake I made in the for loop. The below finally works catching the list of characters. It won't catch * and ? though. I wonder if there wasn't an easier way to do it, beside using "grep".
    #!/bin/bash
    f_varcheck()
      ifs_orig=$IFS
      count=0
      score=0
      while (( count <= ${#1} )); do
        char=${1:$count:1}
        if [ "$score" = "0" ]; then
          wanted_char='~,!,@,#,$,%,^,&,(,),+,`,='
          IFS=$','
          for item in `echo "$wanted_char"`; do
            [ "$item" = "$char" ] && score=1
          done
        fi
        if [ "$score" = "0" ]; then
          wanted_char='{,},|,[,],\,:,",;,<,>,., ,/,'
          IFS=$','
          for item in `echo "$wanted_char"`; do
            [ "$item" = "$char" ] && score=1
          done
        fi
        if [ "$score" = "0" ]; then
          wanted_char=','
          IFS=$' '
          for item in `echo "$wanted_char"`; do
            [ "$item" = "$char" ] && score=1
          done
        fi
      if [ "$score" = "0" ]; then
        (( count += 1 ))
      else
        break
      fi
      done
      IFS=$ifs_orig
      [ "$score" = "1" ] && return 1 || return 0
    read -p "Enter a filename: " fname
    if ! f_varcheck "$fname"; then
       echo "Invalid character \`$char\` found."
    else
       echo "Input is ok."
    fi
    {code}
    Edited by: Dude on Feb 11, 2012 8:51 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to use 'bash' command in java?

    Hi,
    I am using Linux operating system
    when i run the following code, 'test.sh' not started
    ================================================================
    String cmd = "bash \"/home/kulandaivelu/Desktop/works/other's works/test.sh\"";
    Runtime.getRuntime().exec(cmd).waitFor();
    ================================================================
    but it started when i use same command(bash "/home/kulandaivelu/Desktop/works/other's works/test.sh") in terminal
    anyone let me know what mistake i made in the code piece..
    Thanks in Advance
    Kulandaivelu

    Hi,
    thanks a lot..
    I used the following code.. it worked well..
    ===============================================================
    String cmd[] = {"bash","/home/kulandaivelu/Desktop/works other's/test.sh"};
    Runtime.getRuntime().exec(cmd).waitFor();
    ===============================================================
    Thanks a lot again..

  • PS1 String behaving differently - how to get only "/"?

    Hi there, let me first start with the 4 lines of code I use for my PS1 string (in bash)
    boBlack="\[\033[1;30m\]"
    boGreen="\[\033[1;32m\]"
    boCyanOnBlack="\[\033[1;36;40m\]"
    export PS1="$boCyanOnBlack"'${PWD%*/}'"$boBlack/$boGreen"
    Now what does this do?
    It will make a coloured string as part of my current working dir. (Prompt)
    Example:
    If i go to
    cd /home/shevegen
    then my prompt will look like:
    /home/shevegen/
    (I like the trailing / because I can copy/paste easier with it. )
    Now, the problem is when i am doing this:
    cd /
    then I am in /
    and while in konsole it works, in VTE this does not work.
    Does anyone know why this string behaves differently in
    VTE and Konsole? VTE for example does not show any
    / when you are in
    the / root dir
    PS: Anyone has a hint or knows why in VTE and in gnome-terminal this does
    not work?
    Last edited by shevegen (2007-03-19 12:10:39)

    Hi Dennis,
    thanks for your suggestion, unfortunately I already tried that and it didn't work. I have created several unique styles. Problem is, I need two diferent styles in *one paragraph* - one style for the "heading", which is consistent to the APA manual not an own paragraph (sorry, not my idea...), and another style for the following text. As my example above shows, the heading is followed by usual text and I may not press return after the heading and switch to a new paragraph..
    It has to look exactly like this:
    +heading in italics.+ Now heading is followed by usual text without changing the paragraph or starting a new line. Blurb blurb blurb whatsoever blurb blurb. The text goes on an on and an on you see.
    I can't format the heading differently than the text (because if I try, the whole paragraph is formatted this way) and so I can't add just the heading to the TOC. Do you see what my problem is? Got any other suggestion?

  • Bash command in title?

    how do i put the command in my title? i'm playing around with $BASH_COMMAND but cant get it to work. here's the relevant section i have now in my bashrc:
    PROMPT_COMMAND='echo -ne "\033]0;${USER}: ${PWD/$HOME/~}\007"'
    thanks for any and all help.

    Hi,
    thanks a lot..
    I used the following code.. it worked well..
    ===============================================================
    String cmd[] = {"bash","/home/kulandaivelu/Desktop/works other's/test.sh"};
    Runtime.getRuntime().exec(cmd).waitFor();
    ===============================================================
    Thanks a lot again..

  • How to encrypt file on linux using Gnupg command in Java Embedding in BPEL.

    Hi All,
    I am trying to invoke a command script using the java embedding in BPEL Process.I am using the below code to execute the particular command to encrypt the file :-
    try {    
            Runtime rt = Runtime.getRuntime();    
    Process pr = rt.exec(new String[] {"/bin/bash", "-c", "/u01/GnuPG/bin/gpg", "-e", "-r", "Developer","/u01/oracle/ConfigFiles/Adapter_controlDir/abc.csv"});    
             int exitVal = pr.waitFor();            
            String result = "SUCCESS: Process exit with " + exitVal;         
            addAuditTrailEntry("result = "+result);      
            setVariableData("outputVariable","payload","/client:processResponse/client:result",result);    
    } catch(Exception e) {    
            e.printStackTrace();      
      String result = "FAILURE: Exception with " + e.toString();    
            addAuditTrailEntry("result = "+result);      
            setVariableData("outputVariable","payload","/client:processResponse/client:result",result);    
    The above statement does nothing. I am not sure what command i need to use to access to the command line.
    When i try this particular statement from linux machine command prompt :- /u01/GnuPG/bin/gpg -e  -r  Developer /u01/oracle/ConfigFiles/Adapter_controlDir/abc.csv
    It works absolutely fine and it creates the encrypted files also.
    Please suggest , which command i need to use from the java embedding.
    Please suggest!!
    Regards,
    Shah

    I think, you can try, writing these commands into a separate shell script and call that shell script from bpel via Java embedding. However, you might not get a return response.. but you can still give a shot.
    Hope it helps.

  • Running a "heavy" program from within a java class

    Dear Java programmers,
    I 'm trying to run a software called surflex from within a java class, using the following java command:
    Runtime.getRuntime().exec( new String[ { "/bin/bash", "docking_script_2.bash"} );
    For convenience I've created the following simple bash script but for some strange reason surflex is not executed:
    #!/bin/bash
    surflex-dock-v211-linux.exe proto drug.mol2 receptor_hydro.mol2 p1;
    surflex-dock-v211-linux.exe dock drug.mol2 p1-protomol.mol2 receptor_hydro.mol2 >& 1OHR_A_output.txt;
    Can anybody help me on that (ignore the arguments, they are correctly set)? I'll try to find another, more generic example, but so far I've noticed that the same thing happens with unix grep command.
    thanks,
    Tom

    I think if you want to invoke a bash shell and give it a command to execute, you need to do
    /bin/bash -c commandrather than
    /bin/bash commandAccordingly, your call to exec should look like
    exec( new String[ { "/bin/bash", "-c" "docking_script_2.bash"} );Beyond, that, I'd suggest the following as general debugging tips and best practices:
    * As the first line of the bash script, include a line that does something simple, like touch a file, so you can see if the script is executing at all.
    * In Java, call Process.waitFor(). Its return value is the process' exit value.
    * Make sure you're gobbling stdout and stderr from the process, and giving stdin any input it needs. You'll have to do this for the process to run correctly, and you can also use what you read from stdout and stderr to debug the execution of the process. [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]
    * You may wan to look into ProcessBuilder, rather than Runtime.exec. I haven't used it myself yet, but apparently it's supposed to be the preferred way to execute external processes.

  • Execution of a command in Linux

    Hi expert,
    I wrote this java class, that it's working in Windows, but not in Linux.
    Seems not executing the code have you any idea why?
    1) you provide a userlogin
    2) check if the userlogin file exists
    3) if not it create a file where name and content should be the userlogin.
    for exampe, you provide "John" and it will create /home/oracle/JOHN that contains the string "JOHN".
    thank you
    import java.io.*;
    public class RemoteScript {
         static String mDirectoryPath = "/home/oracle/";
         static String mCompleted = "COMPLETED";
         static String mError = "ERROR";
         private static boolean checkFile(String pFileName) {
              File f = new File(pFileName);
              return (f.exists() ? true : false);
         private static boolean execute(String pInstruction) {
              boolean oResult=false;
              int exitVal = -1;
              try {
                   Runtime rt = Runtime.getRuntime();
                   Process proc = rt.exec(pInstruction);
                   BufferedReader br = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
                   String line;
                   while ((line = br.readLine()) != null) {
                        System.out.println(line);
                   exitVal = proc.waitFor();
                   if(exitVal==0)
                        oResult=true;
                   } catch (Throwable t) {
                        t.printStackTrace();
              return oResult;
         public static String createUser(String pLogin) {
              String oFileName = mDirectoryPath + pLogin.toUpperCase();
              if (!checkFile(oFileName)) {
                   String oInstruction = "/bin/echo " + pLogin.toUpperCase() + " > "+ oFileName;
                   execute(oInstruction);
                   if (checkFile(oFileName)){
                        return mCompleted;
                   else{
                        return mError + ".NT";
              } else
                   return mError + ".EX";
         public static void main(String[] args) {
              createUser("SAMPLEUSER");
    }Edited by: sabre150 on Feb 21, 2012 5:06 PM
    Moderator action : { code } tags added

    I don't understand how that code can be working under windows but ...
    You have a fundamental misunderstanding. Under Linux the ">" operator has to be interpreted by a shell. This means you need use the array version of Runtime.exec() and make your command
               String[] oInstruction = {"bash", "-c","/bin/echo " + pLogin.toUpperCase() + " > " + oFileName};and change your execute() method to have signature
       private static boolean execute(String[] pInstruction)You are also not handling the Process 'stderr' stream at all. You should read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and implement ALL the recommendations. Failure to do so may cause you significant hair loss.
    P.S. I have used 'bash' but you are free to use any shell you want but make sure you read the appropriate shell man page.
    Edited by: sabre150 on Feb 21, 2012 5:23 PM

  • How to use cvs checkout command in java

    Hi,
    I am using Ubuntu
    I have installed cvs client in ubuntu
    I have one problem running 'cvs checkout' command through java..
    "cvs" -d ":ext:[email protected]:/var/cvs" co -P "Auto/test"
    When i run the above command in terminal, i got one prompt like '[email protected]'s password:' in the terminal if i give the valid password the folder 'Auto' checked out successfully..
    I have tried following steps but i don't know how to give the password to the terminal using java
    First i created the 'checkout.sh' file.
    In this i have typed "cvs" -d ":ext:[email protected]:/var/cvs" co -P "Auto/test"
    Then i call it using java by the following code
    =================================================================
    String cmd[] = {"bash","checkout.sh"};
    Runtime.getRuntime().exec(cmd).waitFor();
    =================================================================
    Anyone let me know how do I achieve this in java?
    Thanks in Advance
    Kulandaivelu

    masijade. wrote:
    PhHein wrote:
    Maybe you need to modify your links to be more obvious :P
    [*>>klick me<<*|http://www.jcvs.org/]
    Nah! Attention to detail is one of most crucial attributes for a programmer in any language. ;-)
    Edit: The urls seemingly don't like h1 and color tags. ;-)Nope, they don't and I couldn't be bothered to try.
    Gratz on Gold!

  • Java.lang.Runtime.exec problem in ubuntu 9.10

    Hi:
    I tried to run some command in the java code , for example "grass64 -text /home/data/location", this command works well in the terminal, however when I call it in the java code I got some excepetions.
    My code is :
    public class Grass {
         public static String grassBatJob="GRASS_BATCH_JOB";
         public void run(String cmd,String jobPath) {
              //set the environments variables
              Map<String, String> env=new HashMap<String, String>();
              env.put(grassBatJob, jobPath);
              String gisDataBase="/home/kk/grass/GrassDataBase";
              String location="spearfish60";
              String mapset="PERMANENT";
              cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
              CommandLine line=new CommandLine(cmd);
              //the real cmd should be >>grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT
              System.out.println("start line=="+line.toString());
              DefaultExecutor de=new DefaultExecutor();
              try {
                   int index=de.execute(line,env);
                   System.out.println(index);
              } catch (ExecuteException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              String jobPath=Grass.class.getResource("grass.sh").getFile();
              new Grass().run("grass64 -text", jobPath);
    The real cmd I want to execute is "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in my application I got the exception"
    java.io.IOException: Cannot run program "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException: error=2, No such file or directory
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
         at java.lang.Runtime.exec(Runtime.java:593)
         at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
         at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
         at org.kingxip.Grass.run(Grass.java:27)
         at org.kingxip.Grass.main(Grass.java:38)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
         at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
         at java.lang.ProcessImpl.start(ProcessImpl.java:65)
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
         ... 7 more
    I wonder why?

    Thanks for all of your reply, and now I can run the command, however I met some problems when I tried to get the result of the exec.
    The core codes are shown below:
    String cmd="g.version";
    String[] exe={"bash","-c",cmd};
    Process p1=Runtime.getRuntime.exec(exe,env); // the env has been set
    GrassThread outThread=new GrassThread("out", p1.getInputStream());
    outThread.start();
    GrassThread errorThread=new GrassThread("error", p1.getErrorStream());
    errorThread.start();
    int exitVal = p1.waitFor();
    String resu=outThread.sb.toString();
    System.out.println("==========the output start========");
    System.out.println(resu);
    System.out.println("==========the output end========");
    System.out.println("ExitValue: " + exitVal); //------------------> line one
    public class GrassThread extends Thread{
         public StringBuffer sb=new StringBuffer();
         public GrassThread(String type,InputStream is) {
              this.type=type;
              this.is=is;
         public void run() {
              try {
                   InputStreamReader isr = new InputStreamReader(is);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ((line = br.readLine()) != null) {
                        System.out.println(type + ">" + line);
                        sb.append(line).append("\r");  // ----------------------------> line two
    }I define a StringBuffer in the GrassThread to save the output (see the code where I marked by "line two"), and when the process complete, I check the StringBuffer to get the output (see code where I marked by "line one"), however the output in the console of the IDE are :
    ----------- output in the console of the IDE start -------------
    ==========the output start========
    ==========the output end========
    ExitValue: 0
    out>GRASS 6.4.0RC5 (2009)
    ----------output in the console of the IDE end--------------------
    I can not understand, in the code "line one", I first get the output using "System.out.println(resu);",then I print the exitvalue,but why the order of the output in the console is not what I expected?
    Another question, the code above assume the output can be got from the Process's getInputStream, however sometimes the output maybe come from the Process's getErrorStream, so how to handle it?
    Edited by: apachemaven on 2010-3-5 ??5:38

  • Trying to execute shell process in Linux

    Hi. I'm trying to execute a simple command in the form of 'bash -c "ls ~root ~"' from within java. I've tried using both the java.lang.Runtime.exec() methods and the java.lang.ProcessBuilder class but both produce the same error message (which I get from the OutputStream of the Process):
    bash: ls ~root ~: command not found
    A command such as 'bash -c "ls"' succeeds, providing the contents of my home directory in the Process's InputStream that I can display from within the program, but one in which there are one or more arguments to 'ls' fails the same way as above.
    It seems that when I have a 'bash -c "ls <arguments>" as the command from within java, bash believes that the entire argument in double quotes ("ls <arguments>") is the command. It doesn't seem to "see" the spaces.
    Would anyone know what I might do in this case? Below is my code:
    import java.util.ArrayList;
    import java.io.*;
    public class ShellCommand {
        public static void main(String args[]) {
            ArrayList<String> shellCommandLine = new ArrayList<String>(3);
            shellCommandLine.add("bash");
            shellCommandLine.add("-c");
            shellCommandLine.add("\"ls ~root ~\"");
            InputStream is = null;
            ProcessBuilder pb = new ProcessBuilder(shellCommandLine);
            pb.redirectErrorStream(true);
            try {
                Process p = pb.start();
                is = p.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                String line;
                while ((line = br.readLine()) != null) {
                    System.out.println(line);
                br.close();
            } catch (IOException ie) {
                System.out.println("Error executing external process.\n");
                System.exit(1);
    }

    I have just used Runtime.exec() on        final String[] command = {"bash","-c", "ls ~root ~" };As expected, the stderr stream produces
    ls: /root: Permission denied
    and stdout produces a directory listing of ~ (my home directory).
    You should read the man page for bash -c and read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html to see how to handle stdout and stderr.

  • Oem 12.1.0.3 installer fails with ora-01017

    Greetings,
    I am attempting to upgrade my OEM 12.1.0.1 installation to 12.1.0.3. I am following the instructions in the Oracle Enterprise Manager Cloud Control Upgrade Guide and Oracle Support Note 1568143.1. I have verified that all prerequisites are met and have installed patch 11061801 to the repository. The repository and OMS are on different machines. The 12.1.0.1 installation is able to connect to the repository, it has been running successfully for some time now. On the OMS server I stopped the OMS and the Agent and I invoke the 12.1.0.3 installer. I follow the steps and when it gets to the connection page it fails with ORA-01017. The messages are shown -
    1. Verify if the SYS password you entered is valid.
    2. Verify if the database initialization parameter REMOTE_LOGIN_PASSWORDFILE is set to either Shared or Exclusive.
    3. Verify if a password file with the file name orapw<SID> exists in the <ORACLE_HOME>/dbs directory.
    All conditions are met:
    -bash-3.2$ echo $ORACLE_SID
    oemrepos
    SQL> connect sys as sysdba
    Enter password:
    Connected.
    SQL> connect sysman
    Enter password:
    Connected.
    SQL> show parameter remote_login_passwordfile
    NAME                                 TYPE        VALUE
    remote_login_passwordfile            string      EXCLUSIVE
    -bash-3.2$ ls -l $ORACLE_HOME/dbs/orapwoemrepos
    -rw-r----- 1 oracle dba 1536 Jan 30  2013 /usr/local/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapwoemrepos
    I am able to connect remotely from another machine. sqlplus is not installed on the OMS server.
    I am completely stumped and in need of assistance. Searching the web only indicates that I need to insure that the above listed conditions should be met, they are. If anyone has any suggestions I would appreciate the help.
    Thank you.
    Bill Wagman

    On repository server , can you login as sys user ?
    Try to connect through listener and share the result.
    sqlplus sys/<password>@<connectstring> as sysdba
    Thanks
    Rajesh

  • Execute UNIX  script from java not working

    Hi
    I am having difficulty running my java program to execute UNIX script on a Windows box. Here is my code.
    public boolean executeScript() {
              try {
                   String testScript= "WEB-INF/scripts/test.sh";
                   File file = new File(copyToQaScript);
                   System.out.println(file.getAbsolutePath());
                   Process proc = Runtime.getRuntime().exec(file.getAbsolutePath());
              } catch (IOException ioe) {
                   ioe.printStackTrace();
                   logger.error(ioe);
              } catch (RuntimeException re) {
                   re.printStackTrace();
                   logger.error(re);
              } catch (Exception e) {
                   e.printStackTrace();
                   logger.error(e);
              return true;
         }When I execute this method, I am getting IOException as below.
    java.io.IOException: CreateProcess: C:\tomcat-5.0.28\webapps\myProject\WEB-INF\scripts\test.sh error=193
    Can anyone help me? Thanks.

    kminkeller wrote:
    Yes I have Cygwin installed. I am quite aware of that thanks Sabre.Then you need something like
          String[] command = {"bash","/home/sabre/bin/fred.sh"};
            Process p = Runtime.getRuntime().exec(command);
      if the executabe directory (/home/sabre/bin in my case) is not on the PATH or
          String[] command = {"bash","fred.sh"};
            Process p = Runtime.getRuntime().exec(command);
      if it is.

  • Stuck with problem using waitFor()

    Hi,
    I wrote a program which will run in a loop like this
    for(int i=0;i<theme_caseidVec.size();i++)
    String proj_theme="",proj_case_id="",repository_name ="";
    String[] Details=new String[2];
    Details=(String[])theme_caseidVec.get(i);
    proj_theme = Details[0];
    proj_case_id = Details[1];
    repository_name = (String)CVSRepoHash.get(proj_theme);
    path = properties.getProperty(proj_case_id);
    if(proj_theme!= null && proj_case_id!= null && repository_name!= null && !repository_name.equals("0") && path!= null)
    System.out.println("repository_name: "+repository_name+"proj_theme: "+proj_theme+"proj_case_id :"+proj_case_id);
    res = checkoutByProj(repository_name,proj_theme,path);
    and i will be invoking the following method each time for more than 200 times.
    public synchronized int checkoutByProj(String repository_name,String proj_theme,String proj_path)
    String cmd = "";
    int i=0;
    cmd = "bash /home/abc/cvsCheckoutProj.sh ";
    cmd = cmd.concat(repository_name.trim());
    cmd = cmd.concat(" ");
    cmd = cmd.concat(proj_theme.trim());
    cmd = cmd.concat(" ");
    cmd = cmd.concat(proj_path.trim());
    File workDir = new File("/home/abc");
    try
    System.out.println("Command:" + cmd);
    Process p = Runtime.getRuntime().exec(cmd, null, workDir);
    i = p.waitFor();
    catch(Exception e)
    System.out.println(e);
    cmd = "";
    return i;
    But i am not able to fully execute this code till the end.
    Its geting hanged and nothing is displayed in the console.
    Can any one suggest me the solution for this problem.

    String[] cmd = {"bash", "-c", "/home/abc/cvsCheckoutProj.sh", repository_name.trim()), proj_theme.trim(), proj_path.trim()};
    File workDir = new File("/home/abc");
    Process p = Runtime.getRuntime().exec(cmd, null, workDir);Make sure you handle the Process stdout and stderr as recommended in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .

Maybe you are looking for