Hi,

I am trying to write an applicaiton which will run 2 zip files (one after another) with minimum user input.

I can get the file to run but it is then waiting for the user to select "Unzip" to unzip the file. I was wondering if there is a parameter that I can pass to run it without the user selecting "Unzip".

Code I have so far is....

import java.lang.*;
import java.io.*;

public class RunUpdate {
	
	public static void main(String[] args) throws IOException{ {
		//Run First Zip File
		Runtime r = Runtime.getRuntime();
		Process p = null;
		
		try{
			String s = "C:\\Test\\zipFile.exe";
			p = r.exec(s);
						
		}
		catch(Exception e){
			System.out.println("error==="+e.getMessage());
			e.printStackTrace();
		}
		
		//Then run Second Zip file etc

		}
	}
}

Search for a command line option to unzip with the program you're using, then execute it in the same way you did to start the program.

Are you talking about .zip file or .rar file?

If it is zip file , you can use the unzip command.

unzip mydir.zip

Search for a command line option to unzip with the program you're using, then execute it in the same way you did to start the program.

Hi, thanks for your reply.

I am assunming that there is no way to extract it using windows zip?

I have done a bit of searching and am going to try 7zip, the cmd line parameter is -y to asssume yes to all questions.

You don't have any good examples of 7zip use in java? I have been searching but finding it hard to locate anything of much use.

I am assunming that there is no way to extract it using windows zip?

If you are talking about .zip file , then you can unzip it using windows unzip command.

If you want , you can check it manually using command prompt

Open your command prompt and go to the diretory where the zip file is present and use the unzip command.

Ex. unzip hello.zip

The above command works perfectly and even it wont asks for user conformation .

You can write the same command in your java program.....Why going for another 7zip application.?

What program created the zipFile.exe file?
Is there any documentation about how to execute the .exe it creates in batch mode?

The unzip command is only valid for .zip files, in Windows (EDIT: apologies, works in Linux as well), which are 2 rather big and unnecessary constraints.

Documentation of the program is the way to go.

Hi,

thanks for the replies.

From checking the properties of the file it was created with winzip and is an exe not a zip.

I can get it to run from the java code, just need to find a working example of how to pass a parameter /y ?? to assume yes to all questions.

how to pass a parameter

Append it after the command name.

thanks guys got it sorted.

the switch that I was looking for was /auto from here:
http://kb.winzip.com/kb/entry/115/

Code now looks like this (for anybody else in same situation)

public class RunCleanWaterUpdate {

	public static void main(String[] args) throws IOException{ {
		//Run First Update
		Runtime r = Runtime.getRuntime();
		Process p = null;
		
		try{
			String updateFilePath = "C:\\Test\\firstFile.exe /auto";
			p = r.exec(updateFilePath);
			//Wait for the file to be extracted before continuing 	
			p.waitFor();
						
		}
		catch(Exception e){
			System.out.println("error==="+e.getMessage());
			e.printStackTrace();
		}
		
		//Run Second Update File
		try{
			String updateFilePath2 = "C:\\Test\\secondFile.exe /auto";
			p = r.exec(updateFilePath2);
                        //Wait for the file to be extracted before continuing 	
			p.waitFor();
						
		}
		catch(Exception e){
			System.out.println("error==="+e.getMessage());
			e.printStackTrace();
		}

thanks very much for all your help guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.