Can not move rar archives because the packing of them have not yet finished

Hello,
I have a thread wherein I execute the rar.exe cmd line version to compress folders in .rar archives, now after packing them I want to copy them for example to another directory on my hard disk with a java "copyfile" command. The problem is that before all .rar archives are packed or before rar.exe even started to pack the folders at all to .rar archives the "copyfile" command has already been executed by java, but there arent any .rar files because the Runtime.getRuntime().exec method which calls the rar.exe is still busy with packing the .rar archives. So the solution to this problem is to query the Runtime.getRuntime().exec method wether the rar.exe process has already been finished like:
if (Runtime.getRuntime().exec != finished)
  dont know what to write here...
else
   copy the .rar files
}I also tried this but there is no go :
Process rar =  Runtime.getRuntime().exec("./7za.exe a -m9 -r -y -tzip -- H:/bla"+i+".zip H:/*.*");
rar.waitFor();-----------------------------------------------------------------------------
because only the first part .rar archiv gets compressed but stopped when it reached 2KB in size :-) ...
so anyhow the waitFor() method is breaking my whole thread where also the rar.exe is executed!
public void actionPerformed(ActionEvent e)
          if(e.getSource().equals(buttonPack))
              try
                meinThread = new PackThread();
                //meinThread.setPriority(Thread.MAX_PRIORITY);
                meinThread.start();
              catch(Exception a)
                a.printStackTrace();
public class PackThread extends Thread
         PackThread()
         public void run()
              filesizeNew = filesizeCombo.getSelectedItem().toString().substring(0,filesizeCombo.getSelectedItem().toString().length() - 3).trim();
              String filenameNew = rlsFilenameTF.getText().trim();
              String verzeichnisName = rlsSourceDirectoryCB.getSelectedItem().toString();
              String targetDir = SettingsPanel.targetDirDefaultTF.getText();
              String rarFormat = targetDir+"/"+verzeichnisName+"/"+filenameNew+".rar";
              String verzeichnisNameZielAbsolut = SettingsPanel.targetDirDefaultTF.getText().trim();
              verzeichnisNameQuelleAbsolut = SettingsPanel.sourceDirDefaultTF.getText();
              sourceDirProper = verzeichnisNameQuelleAbsolut.replaceAll("\\\\", "/");
              String tempDir = targetDir + "/" + verzeichnisName;
              File f = new File(tempDir);
              f.mkdirs(); 
             try
               Process p = Runtime.getRuntime().exec("./rar.exe a -r -m5 -mm -md4096 -vn -y -v" + filesizeNew +"k "+rarFormat+" "+sourceDirProper+"/"+verzeichnisName+"/*.*" );
p.waitFor();   // This dont work as I said above in the text
// here should be the copyfile or whatever command which needs the .rar archives to do something with them, so they must already be created before this command here is called!
              catch(Exception a)
                a.printStackTrace();
      }  

hello,
sorry, but I dont understand what you mean because my native language is not english and I am coding in javag since about 6 months so I am still a newbie :-)
can you explain me a bit more about this problem?
furthermore I have made a workaround now which gets me fever cpu load than than before:
------------------------------------Parts of the code---------------------------------------------------------------
try
                Process p = Runtime.getRuntime().exec("./rar.exe a -r -m5 -mm -md4096 -vn -y -v" + filesizeNew +"k "+rarFormat+" "+sourceDirProper+"/"+verzeichnisName+"/*.*" );
                BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String tmp;             
                while((tmp = br.readLine()) != null)
                }because of the while loop the "copyfile" command coming after this code will be executed to the right time!
But still I would like to have a better solution not such a workaround...but maybe I have discovered the best workaround at all who knows :P

Similar Messages

Maybe you are looking for