Can not move rar archives because of the notfinished packing

Status
Nicht offen für weitere Antworten.

PELLE

Bekanntes Mitglied
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 :
-------------------------------------------------------------------------------

Code:
Process rar = Runtime.getRuntime().exec("./rar.exe a -r -m5 -mm -md4096 -vn -y -v" + filesizeNew +"k "+rarFormat+" "+sourceDirProper+"/"+verzeichnisName+"/*.*" );
 
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!
Code:
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();
	         }
	     }
}



----------------------------

Code:
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();
	         }
         }
      }
 
B

Beni

Gast
Wenn ich dem Artikel folge, würde sowas vorgeschlagen:

Code:
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+"/*.*" );

/////// Aus dem Artikel. Die Klasse StreamGobbler findet man auch im Artikel
              StreamGobbler errorGobbler = new
                StreamGobbler(p.getErrorStream(), "ERROR");            
            
            // any output?
            StreamGobbler outputGobbler = new
                StreamGobbler(p.getInputStream(), "OUTPUT");
                
            // kick them off
            errorGobbler.start();
            outputGobbler.start();

//////// fertig Artikel

                p.waitFor();
             }     
            catch(Exception a)
            {
              a.printStackTrace();
            }
         }
      }

Ohne irgendwelche Garantien...
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben